0
\$\begingroup\$

getMusicPlaying is set to false whenever someone touches the button, but libgdx runs show method only once, at the start of the game, hence the music will keep playing forever.

I tried to use the render and batch.begin instead of show() same result.

private boolean musicPlaying = true;

button.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
 return true;
}

public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
 setMusicplaying(!musicplaying);
}
});

}
});
}

public void show() {
 if (getMusicPlaying ==true)
  music.play();
}
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

In your setMusicplaying function, you should add something like music.stop() whenever the argument is false.

\$\endgroup\$
1
  • \$\begingroup\$ thats why i love stackexchanges websites, thank you \$\endgroup\$
    – Lynob
    Commented Feb 8, 2017 at 12:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .