Skip to content

Commit

Permalink
Merge pull request #41 from gedehari/freeplay-thread
Browse files Browse the repository at this point in the history
BUG BUG BUG BUG BUG (Freeplay thread cont'd)
  • Loading branch information
Yoshubs authored Sep 23, 2021
2 parents dc68102 + 3e9b94b commit 2203717
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions source/gameFolder/meta/state/menus/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FreeplayState extends MusicBeatState
var intendedScore:Int = 0;

var songThread:Thread;
var threadActive:Bool = true;

private var grpSongs:FlxTypedGroup<Alphabet>;
private var curPlaying:Bool = false;
Expand Down Expand Up @@ -215,7 +216,7 @@ class FreeplayState extends MusicBeatState

if (controls.BACK)
{
songThread.sendMessage(-1);
threadActive = false;
Main.switchState(this, new MainMenuState());
}

Expand All @@ -234,7 +235,7 @@ class FreeplayState extends MusicBeatState
if (FlxG.sound.music != null)
FlxG.sound.music.stop();

songThread.sendMessage(-1);
threadActive = false;

Main.switchState(this, new PlayState());
}
Expand Down Expand Up @@ -326,22 +327,22 @@ class FreeplayState extends MusicBeatState
{
while (true)
{
if (!threadActive)
{
trace("Killing thread");
return;
}

var index:Null<Int> = Thread.readMessage(false);
if (index != null)
{
if (index == -1)
{
trace("Killing thread");
return;
}

if (index == curSelected && index != curSongPlaying)
{
trace("Loading index " + index);

var inst:Sound = Sound.fromFile('./' + Paths.inst(songs[curSelected].songName));

if (index == curSelected)
if (index == curSelected && threadActive)
{
FlxG.sound.playMusic(inst);

Expand Down

0 comments on commit 2203717

Please sign in to comment.