Skip to content

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

@sebbernery

Description

@sebbernery

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 !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions