fix crash when going back to title

This commit is contained in:
MtH 2021-04-22 21:36:56 +02:00
parent 2afb1a2801
commit 69871d096c
2 changed files with 80 additions and 89 deletions

View File

@ -260,7 +260,10 @@ class MainMenuState extends MusicBeatState
menuItems.enabled = false; menuItems.enabled = false;
if (controls.BACK && menuItems.enabled && !menuItems.busy) if (controls.BACK && menuItems.enabled && !menuItems.busy)
{
FlxG.sound.play(Paths.sound('cancelMenu'));
FlxG.switchState(new TitleState()); FlxG.switchState(new TitleState());
}
super.update(elapsed); super.update(elapsed);
} }

View File

@ -48,6 +48,7 @@ import sys.thread.Thread;
class TitleState extends MusicBeatState class TitleState extends MusicBeatState
{ {
public static var initialized:Bool = false; public static var initialized:Bool = false;
var startedIntro:Bool;
var blackScreen:FlxSprite; var blackScreen:FlxSprite;
var credGroup:FlxGroup; var credGroup:FlxGroup;
@ -73,6 +74,8 @@ class TitleState extends MusicBeatState
// FlxG.bitmap.clearCache(); // FlxG.bitmap.clearCache();
#end #end
startedIntro = false;
FlxG.game.focusLostFramerate = 60; FlxG.game.focusLostFramerate = 60;
swagShader = new ColorSwap(); swagShader = new ColorSwap();
@ -222,20 +225,11 @@ class TitleState extends MusicBeatState
new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4)); new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4));
FlxTransitionableState.defaultTransOut = new TransitionData(FADE, FlxColor.BLACK, 0.7, new FlxPoint(0, 1), FlxTransitionableState.defaultTransOut = new TransitionData(FADE, FlxColor.BLACK, 0.7, new FlxPoint(0, 1),
{asset: diamond, width: 32, height: 32}, new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4)); {asset: diamond, width: 32, height: 32}, new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4));
}
transIn = FlxTransitionableState.defaultTransIn; if (FlxG.sound.music == null || !FlxG.sound.music.playing)
transOut = FlxTransitionableState.defaultTransOut; {
// HAD TO MODIFY SOME BACKEND SHIT
// IF THIS PR IS HERE IF ITS ACCEPTED UR GOOD TO GO
// https://github.com/HaxeFlixel/flixel-addons/pull/348
// var music:FlxSound = new FlxSound();
// music.loadStream(Paths.music('freakyMenu'));
// FlxG.sound.list.add(music);
// music.play();
FlxG.sound.playMusic(Paths.music('freakyMenu'), 0); FlxG.sound.playMusic(Paths.music('freakyMenu'), 0);
FlxG.sound.music.fadeIn(4, 0, 0.7); FlxG.sound.music.fadeIn(4, 0, 0.7);
} }
@ -331,6 +325,7 @@ class TitleState extends MusicBeatState
if (FlxG.sound.music != null) if (FlxG.sound.music != null)
FlxG.sound.music.onComplete = function() FlxG.switchState(new VideoState()); FlxG.sound.music.onComplete = function() FlxG.switchState(new VideoState());
startedIntro = true;
// credGroup.add(credTextShit); // credGroup.add(credTextShit);
} }
@ -353,8 +348,10 @@ class TitleState extends MusicBeatState
override function update(elapsed:Float) override function update(elapsed:Float)
{ {
#if debug
if (FlxG.keys.justPressed.EIGHT) if (FlxG.keys.justPressed.EIGHT)
FlxG.switchState(new CutsceneAnimTestState()); FlxG.switchState(new CutsceneAnimTestState());
#end
/* /*
if (FlxG.keys.justPressed.R) if (FlxG.keys.justPressed.R)
@ -372,9 +369,7 @@ class TitleState extends MusicBeatState
// FlxG.watch.addQuick('amp', FlxG.sound.music.amplitude); // FlxG.watch.addQuick('amp', FlxG.sound.music.amplitude);
if (FlxG.keys.justPressed.F) if (FlxG.keys.justPressed.F)
{
FlxG.fullscreen = !FlxG.fullscreen; FlxG.fullscreen = !FlxG.fullscreen;
}
var pressedEnter:Bool = FlxG.keys.justPressed.ENTER; var pressedEnter:Bool = FlxG.keys.justPressed.ENTER;
@ -382,17 +377,10 @@ class TitleState extends MusicBeatState
for (touch in FlxG.touches.list) for (touch in FlxG.touches.list)
{ {
if (touch.justPressed) if (touch.justPressed)
{
pressedEnter = true; pressedEnter = true;
} }
}
#end #end
if (FlxG.keys.justPressed.FIVE)
{
FlxG.switchState(new CutsceneAnimTestState());
}
var gamepad:FlxGamepad = FlxG.gamepads.lastActive; var gamepad:FlxGamepad = FlxG.gamepads.lastActive;
if (gamepad != null) if (gamepad != null)
@ -456,9 +444,7 @@ class TitleState extends MusicBeatState
} }
if (pressedEnter && !skippedIntro && initialized) if (pressedEnter && !skippedIntro && initialized)
{
skipIntro(); skipIntro();
}
/* /*
#if web #if web
if (!initialized && controls.ACCEPT) if (!initialized && controls.ACCEPT)
@ -476,16 +462,10 @@ class TitleState extends MusicBeatState
// swagShader.hasOutline = !swagShader.hasOutline; // swagShader.hasOutline = !swagShader.hasOutline;
if (controls.UI_LEFT) if (controls.UI_LEFT)
{
swagShader.update(-elapsed * 0.1); swagShader.update(-elapsed * 0.1);
// alphaShader.update(-elapsed * 0.1);
}
if (controls.UI_RIGHT) if (controls.UI_RIGHT)
{
swagShader.update(elapsed * 0.1); swagShader.update(elapsed * 0.1);
// alphaShader.update(elapsed * 0.1);
}
super.update(elapsed); super.update(elapsed);
} }
@ -526,6 +506,11 @@ class TitleState extends MusicBeatState
{ {
super.beatHit(); super.beatHit();
if (!startedIntro)
return ;
if (skippedIntro)
{
logoBl.animation.play('bump', true); logoBl.animation.play('bump', true);
danceLeft = !danceLeft; danceLeft = !danceLeft;
@ -534,7 +519,9 @@ class TitleState extends MusicBeatState
gfDance.animation.play('danceRight'); gfDance.animation.play('danceRight');
else else
gfDance.animation.play('danceLeft'); gfDance.animation.play('danceLeft');
}
else
{
FlxG.log.add(curBeat); FlxG.log.add(curBeat);
// if the user is draggin the window some beats will // if the user is draggin the window some beats will
// be missed so this is just to compensate // be missed so this is just to compensate
@ -596,6 +583,7 @@ class TitleState extends MusicBeatState
} }
lastBeat = curBeat; lastBeat = curBeat;
} }
}
var skippedIntro:Bool = false; var skippedIntro:Bool = false;