Jump to content

Phaser Change State Problem


notalentgeek
 Share

Recommended Posts

I have problem when changing between state, the console always returns this error:

Phaser.StateManager - No state found with the key: StateMain

I have checked that all of my codes work fine, except the error happened when executing this line of code:

this.game.state.start('StateMain');

Can someone point to which error I made?

 

Here are all my code.

index.html

<!DOCTYPE HTML><html><head>	<meta charset = "UTF-8" />	<title>Phaser State Test</title>	<script src = "phaser-2.2.1/build/phaser.js"></script>	<script src = "StateMain.js"></script>	<script src = "StateOpening.js"></script></head><body>	<script type = "text/javascript">		var game = new Phaser.Game(320, 240, Phaser.AUTO);		//States loads.		game.state.add('StateOpening', StateTest.StateOpening);		game.state.add('StateMain', StateTest.StateMain);		//Start the initial state.		game.state.start('StateOpening');	</script></body></html>

StateOpening.js

StateTest = {};StateTest.StateOpening = function(game){	var logo = null;	var logoAnimDefault = null;};StateTest.StateOpening.prototype = {	preload: function(){		this.load.spritesheet('NotalentLogo', 'assets/notalentlogo.png', 128, 32);	},	create: function(){		logo = game.add.sprite(this.game.world.width/2, this.game.world.height/2, 'NotalentLogo');		logo.anchor.setTo(0.5, 0.5);		logoAnimDefault = logo.animations.add('Default', [0, 2], 2, false);		logoAnimDefault.play(2, false);		logoAnimDefault.onComplete.add(this.LogoOnComplete, this);	},	LogoOnComplete: function(sprite, animation){		this.game.state.start('StateMain');	}};

StateMain.js

StateTest = {};StateTest.StateMain = function(game){};StateTest.StateMain.prototype = {	update: function(){		console.log("TEST");	}};
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...