I created a gameover scene in a crafty.js project but it does not run.

  Crafty.scene('gameover', function() {

 var gameOver = function () {

The background music ("bg") doesn't stop playing once the game ends. How do I fix this?

  • \$\begingroup\$ You sure the background music is referenced with "bg"? If you do Crafty.audio.stop() does it stop? \$\endgroup\$ – MichaelHouse Apr 18 '13 at 20:36
  • \$\begingroup\$ It might be. I realised the music did not stop playing because the gameover scene was never reached. So I asked this question. @Byte56 \$\endgroup\$ – gnerkus Apr 19 '13 at 17:02

As Byte56 said

You sure the background music is referenced with "bg"?

And, Are you sure the scene is really changing?

Crafty.scene('gameover',.. );

you have an 'O' instead of 'o' when you call the scene, unless Crafty is case-insensitive when naming entities i don't what is the problem.

  • \$\begingroup\$ I've corrected the "o"s and checked my reference to the background music. The scene doesn't change still. \$\endgroup\$ – gnerkus Apr 19 '13 at 0:48
  • \$\begingroup\$ I've fixed the problem. \$\endgroup\$ – gnerkus Apr 19 '13 at 1:58

I was able to get the transition to work by removing this code:

  function () {
    Crafty.unbind('EnterFrame', appleEvent);

It is the uninit callback for the main game scene. I wonder why it prevented the transition.


Not the answer you're looking for? Browse other questions tagged or ask your own question.