-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing the way FlxStates are called #2565
Changes from 3 commits
01f8ef5
3f72b87
f69464c
cf894af
921d325
706f425
292fe03
bff148b
ba94f73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,10 +367,10 @@ class FlxG | |
* Attempts to switch from the current game state to `nextState`. | ||
* The state switch is successful if `switchTo()` of the current `state` returns `true`. | ||
*/ | ||
public static inline function switchState(nextState:FlxState):Void | ||
public static inline function switchState(nextState:() -> FlxState):Void | ||
{ | ||
if (state.switchTo(nextState)) | ||
game._requestedState = nextState; | ||
if (state.switchTo(nextState())) | ||
game._requestedState = nextState(); | ||
} | ||
|
||
/** | ||
|
@@ -379,7 +379,7 @@ class FlxG | |
*/ | ||
public static inline function resetState():Void | ||
{ | ||
switchState(Type.createInstance(Type.getClass(state), [])); | ||
switchState(() -> Type.createInstance(Type.getClass(state), [])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. once we start storing the state creator function we can just call that to create a new one, rather than needing to use Type.createInstance. with Type.createInstance FlxStates can't have constructor args, by passing in functions we can do things like FlxG.switchState(()->{ return new MyState(arg1, arg2); }); and we'll know how to switch to that state AND reset it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, so like a function? I like it, I like it |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,7 +199,7 @@ class FlxSplash extends FlxState | |
#end | ||
FlxG.stage.removeChild(_sprite); | ||
FlxG.stage.removeChild(_text); | ||
FlxG.switchState(Type.createInstance(nextState, [])); | ||
FlxG.switchState(() -> Type.createInstance(nextState, [])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nextState should also be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm So like making the PlayState.new also in FlxGame? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where before you had addChild(new FlxGame(400, 300, MenuState); now you can just do addChild(new FlxGame(400, 300, MenuState.new); the reason for this is to allow constuctor args, like addChild(new FlxGame(400, 300, MenuState.new.bind(arg)); |
||
FlxG.game._gameJustStarted = true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state.switchTo() should take a
()->FlxState
rather than a FlxState instance, it should store the function in_requestedState
and wait until the new stuff is all set up to call it, creating the state