Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import me.stringdotjar.flixelgdx.logging.FlixelLogger;
import me.stringdotjar.flixelgdx.signal.FlixelSignal;
import me.stringdotjar.flixelgdx.signal.FlixelSignalData.UpdateSignalData;
import me.stringdotjar.flixelgdx.tween.FlixelTween;
import me.stringdotjar.flixelgdx.signal.FlixelSignalData.StateSwitchSignalData;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -96,12 +97,22 @@ public static void initialize(@NotNull FlixelGame gameInstance,
initialized = true;
}

/**
* Sets the current screen to the provided screen, and clears all active tweens by default.
*
* @param newState The new {@code FlixelState} to set as the current screen.
*/
public static void switchState(FlixelState newState) {
switchState(newState, true);
}

/**
* Sets the current screen to the provided screen.
*
* @param newState The new {@code FlixelState} to set as the current screen.
* @param clearTweens Whether to clear all active tweens.
*/
public static void switchState(FlixelState newState) {
public static void switchState(FlixelState newState, boolean clearTweens) {
Signals.preStateSwitch.dispatch(new StateSwitchSignalData(newState));
if (!initialized) {
throw new IllegalStateException("Flixel has not been initialized yet!");
Expand All @@ -113,6 +124,14 @@ public static void switchState(FlixelState newState) {
state.hide();
state.dispose();
}
if (clearTweens) {
FlixelTween.getGlobalManager()
.getActiveTweens()
.forEach(tween -> tween.cancel());
FlixelTween.getGlobalManager()
.getTweenPool()
.clear();
}
game.resetCameras();
state = newState;
state.create();
Expand Down