Jump to content

Phaser Change State Problem


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:


Can someone point to which error I made?


Here are all my code.


<!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>


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');	}};


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


  • Recently Browsing   0 members

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