HaxeFlixel / HaxeFlixel/flixel
Initial State is created before final resizeGame() call
Nobody has claimed this yet.
- Dominant language
- Haxe
- Stars
- 2.2k
- Forks
- 522
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Description
FlxGame.create() currently creates the first FlxState before applying actual stage dimensions:
resetGame();
switchState();
stage.addEventListener(Event.RESIZE, onResize);
resizeGame(FlxG.stage.stageWidth, FlxG.stage.stageHeight);
Since switchState() calls _state.create() the first State is inited before resizeGame() updates FlxG.width, FlxG.height, and active scale mode
This is particularly noticeable on mobile, where stage size differs from initial logical resolution
As a result:
- the first State can initialize using old logical resolution
resizeGame()immediately corrects dimensions afterwards- subsequent states work correctly because they are created after resize
This makes first State behave differently from every subsequent State.
Suggested fix: apply initial size change before creating the first state
resetGame();
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(Event.RESIZE, onResize);
resizeGame(FlxG.stage.stageWidth, FlxG.stage.stageHeight);
switchState();
resizeGame() should also handle fact that _state isn't created yet:
FlxG.resizeGame(width, height);
_state?.onResize(width, height); //if there's no ?. there will be Null Obj Reference
This ensures that first State and all subsequent States are created with same already-calculated game dimensions
Issue is therefore initialization-order problem rather than State-specific or rendering problem
If you need specific examples I can provide them
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at FlxGame.create(), tracing the current resetGame(), switchState(), and resizeGame() order. Check how resizeGame() behaves before _state exists and verify that the first State receives the final dimensions and scale mode, while subsequent State initialization remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100