Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Update logic for the cutscene example in HaxeFlixel
/**
* Update Code - HaxeFlixel
* Kino Rose
*/
class CutsceneState extends FlxState {
//Code from Before
override public function update(elapsed:Float) {
super.update(elapsed);
updateSkip(elapsed);
updateText(elapsed);
}
public function updateSkip(elapsed:Float) {
// Update Percentage that's shown on screen and also controls the visibility of the skip text and bar.
skipPerc = Math.ceil((skipThreshold / SKIP_THRESHOLD) * 100);
if (skipPerc > 0) {
skipBar.visible = true;
skipText.visible = true;
} else {
skipBar.visible = false;
skipText.visible = false;
}
//If the Z key is pressed we start the skip, which prompts the skip bar to show
//Otherwise the bar drains slowly over time
if (FlxG.keys.anyPressed([Z])) {
skipThreshold += elapsed;
} else if (skipPerc < 100 && skipPerc > 0) {
skipThreshold -= elapsed;
}
if (skipThreshold >= SKIP_THRESHOLD) {
transitionToScene();
}
}
//Handles updating the text or switching scenes on the delay is hit
public function updateText(elapsed:Float) {
var currentText = textList[textIndex % textList.length];
if (textIndex < textList.length - 1) {
if (textDelay > currentText.delay) {
transitionText();
}
} else if (textDelay > currentText.delay) {
transitionToScene();
}
textDelay += elapsed;
}
public function transitionText() {
textIndex++;
var currentText = textList[textIndex % textList.length];
sceneText.resetText(currentText.text);
sceneText.start(0.05);
textDelay = 0;
}
//Transitions to a new scene using a simple fade to black
public function transitionToScene() {
FlxG.camera.fade(FlxColor.BLACK, 1, false, () -> {
FlxG.camera.fade(FlxColor.BLACK, 1, true);
FlxG.switchState(nextState);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment