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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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