2
\$\begingroup\$

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

  Crafty.scene('gameover', function() {
    Crafty.background("#ccc");
    Crafty.audio.stop("bg");
  });

 var gameOver = function () {
    Crafty.scene('gameOver');
  };

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

\$\endgroup\$
  • \$\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
2
\$\begingroup\$

As Byte56 said

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

And, Are you sure the scene is really changing?

Crafty.scene('gameOver');
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.

\$\endgroup\$
  • \$\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
1
\$\begingroup\$

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.

\$\endgroup\$

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