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,75 +506,83 @@ class TitleState extends MusicBeatState
{ {
super.beatHit(); super.beatHit();
logoBl.animation.play('bump', true); if (!startedIntro)
return ;
danceLeft = !danceLeft; if (skippedIntro)
if (danceLeft)
gfDance.animation.play('danceRight');
else
gfDance.animation.play('danceLeft');
FlxG.log.add(curBeat);
// if the user is draggin the window some beats will
// be missed so this is just to compensate
if (curBeat > lastBeat)
{ {
for (i in lastBeat...curBeat) logoBl.animation.play('bump', true);
danceLeft = !danceLeft;
if (danceLeft)
gfDance.animation.play('danceRight');
else
gfDance.animation.play('danceLeft');
}
else
{
FlxG.log.add(curBeat);
// if the user is draggin the window some beats will
// be missed so this is just to compensate
if (curBeat > lastBeat)
{ {
switch (i + 1) for (i in lastBeat...curBeat)
{ {
case 1: switch (i + 1)
createCoolText(['ninjamuffin99', 'phantomArcade', 'kawaisprite', 'evilsk8er']); {
// credTextShit.visible = true; case 1:
case 3: createCoolText(['ninjamuffin99', 'phantomArcade', 'kawaisprite', 'evilsk8er']);
addMoreText('present'); // credTextShit.visible = true;
// credTextShit.text += '\npresent...'; case 3:
// credTextShit.addText(); addMoreText('present');
case 4: // credTextShit.text += '\npresent...';
deleteCoolText(); // credTextShit.addText();
// credTextShit.visible = false; case 4:
// credTextShit.text = 'In association \nwith'; deleteCoolText();
// credTextShit.screenCenter(); // credTextShit.visible = false;
case 5: // credTextShit.text = 'In association \nwith';
createCoolText(['In association', 'with']); // credTextShit.screenCenter();
case 7: case 5:
addMoreText('newgrounds'); createCoolText(['In association', 'with']);
ngSpr.visible = true; case 7:
// credTextShit.text += '\nNewgrounds'; addMoreText('newgrounds');
case 8: ngSpr.visible = true;
deleteCoolText(); // credTextShit.text += '\nNewgrounds';
ngSpr.visible = false; case 8:
// credTextShit.visible = false; deleteCoolText();
ngSpr.visible = false;
// credTextShit.visible = false;
// credTextShit.text = 'Shoutouts Tom Fulp'; // credTextShit.text = 'Shoutouts Tom Fulp';
// credTextShit.screenCenter(); // credTextShit.screenCenter();
case 9: case 9:
createCoolText([curWacky[0]]); createCoolText([curWacky[0]]);
// credTextShit.visible = true; // credTextShit.visible = true;
case 11: case 11:
addMoreText(curWacky[1]); addMoreText(curWacky[1]);
// credTextShit.text += '\nlmao'; // credTextShit.text += '\nlmao';
case 12: case 12:
deleteCoolText(); deleteCoolText();
// credTextShit.visible = false; // credTextShit.visible = false;
// credTextShit.text = "Friday"; // credTextShit.text = "Friday";
// credTextShit.screenCenter(); // credTextShit.screenCenter();
case 13: case 13:
addMoreText('Friday'); addMoreText('Friday');
// credTextShit.visible = true; // credTextShit.visible = true;
case 14: case 14:
addMoreText('Night'); addMoreText('Night');
// credTextShit.text += '\nNight'; // credTextShit.text += '\nNight';
case 15: case 15:
addMoreText('Funkin'); // credTextShit.text += '\nFunkin'; addMoreText('Funkin'); // credTextShit.text += '\nFunkin';
case 16: case 16:
skipIntro(); skipIntro();
}
} }
} }
lastBeat = curBeat;
} }
lastBeat = curBeat;
} }
var skippedIntro:Bool = false; var skippedIntro:Bool = false;