Skip to content

Commit

Permalink
FlxState: replace transition functions by switchTo(), closes #1676
Browse files Browse the repository at this point in the history
  • Loading branch information
Gama11 committed Dec 20, 2015
1 parent a8993c0 commit be11c5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
20 changes: 6 additions & 14 deletions flixel/FlxG.hx
Original file line number Diff line number Diff line change
Expand Up @@ -297,26 +297,18 @@ class FlxG
}

/**
* Switch from the current game state to the one specified here.
* 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(State:FlxState):Void
public static inline function switchState(nextState:FlxState):Void
{
//If a transition is required
if (game._state.isTransitionNeeded())
{
//Do the transition and exit early
game._state.transitionToState(State);
return;
}
//Otherwise do the switch normally
else
{
game._requestedState = State;
}
if (state.switchTo(nextState))
game._requestedState = nextState;
}

/**
* Request a reset of the current game state.
* Calls `switchState()` with a new instance of the current `state`.
*/
public static inline function resetState():Void
{
Expand Down
20 changes: 6 additions & 14 deletions flixel/FlxState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,14 @@ class FlxState extends FlxGroup
}

/**
* Checked by FlxG.switchState to see if a transition is required before switching states
* @return
*/
public function isTransitionNeeded():Bool
{
//override in your subclass to enable this functionality
return false;
}

/**
* Perform a visual transition, and when it's complete, call FlxG.switchState
* @param State
* Called from `FlxG.switchState()`. If `false` is returned, the state
* switch is cancelled - the default implementation returns `true`.
*
* Useful for customizing state switches, e.g. for transition effects.
*/
public function transitionToState(State:FlxState):Void
public function switchTo(nextState:FlxState):Bool
{
//override in your subclass to enable this functionality
return true;
}

/**
Expand Down

0 comments on commit be11c5f

Please sign in to comment.