HaxeFlixel / HaxeFlixel/flixel

Custom ScaleMode class: can't modify FlxG.width / FlxG.height

Open
#3,510 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haxe
Stars
2.2k
Forks
522
Avg merge
34m
Merged PRs (30d)
1

Description

Hello !
I tried to make a custom BaseScaleMode subclass to disable the scaling, but I can't modify FlxG.width and FlxG.height from my subclass of BaseScaleMode.

class MyScaleMode extends BaseScaleMode {
    override public function onMeasure(width:Int, height:Int) {
        FlxG.width = width;
        FlxG.height = height;
    }
} 

Gives me the error

[ERROR] src/PlayState.hx:18: characters 14-19

 18 |         FlxG.width = width;
    |              ^^^^^
    | This expression cannot be accessed for writing

[ERROR] src/PlayState.hx:19: characters 14-20

 19 |         FlxG.height = height;
    |              ^^^^^^
    | This expression cannot be accessed for writing

(Here is the error with Haxe 5 but I also have the error with Haxe 4).

The FlxG width / height fields are defined like this:

@:allow(flixel.system.scaleModes)
	public static var width(default, null):Int;

I can make a PR adding a method setFlxGWidth / setFlxGHeight in BaseScaleMode to allow this modification, is this a good solution for you ?

Have a nice day !

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with BaseScaleMode.onMeasure and the FlxG width and height declarations shown in the issue. Check how the scale-mode package is granted access and use the compiler error as the initial validation. Done means a custom BaseScaleMode can update both dimensions without write-access errors while existing scaling behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.