Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Byte56, Anko, Josh Petrie, bummzack, msell Apr 25 '13 at 8:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

2 Answers 2

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.

share|improve this answer
    
I've corrected the "o"s and checked my reference to the background music. The scene doesn't change still. –  gnerkus Apr 19 '13 at 0:48
    
I've fixed the problem. –  gnerkus Apr 19 '13 at 1:58
    
Thanks for the new tag, @Tetrad –  gnerkus Apr 19 '13 at 2:00
up vote 1 down vote accepted

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.

share|improve this answer

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