edmundg86

Adding and switching states

Recommended Posts

Sorry I am a complete noob with Phaser so please excuse my lack of knowledge.

 

I am trying to create my first game using states (I have completed the phaser tutorial).

I have created 5 js files one for each state all declared as below:

/// <reference path="phaser.js" />/// <reference path="load.js" />var ABC = {};ABC.Boot = function () { };ABC.Boot.prototype = {    preload: function () {            },    create: function () {            }}

I have created a game.html file as below:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    <title>Water!</title>    <script type="text/javascript" src="js/phaser.js"></script>    <script type="text/javascript" src="js/boot.js"></script>    <script type="text/javascript" src="js/game.js"></script>    <script type="text/javascript" src="js/preload.js"></script>    <script type="text/javascript" src="js/title.js"></script>    <script type="text/javascript" src="js/load.js"></script>    <script type="text/javascript">        (function () {            var game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameContainer');            game.state.add("Boot", ABC.Boot);            game.state.add('preload', ABC.Preload);            game.state.add('title', ABC.Title);            game.state.add('play', ABC.Play);            game.state.start('Boot');        })();    </script></head><body></body></html>

I am getting the following error when trying to start up the game:

 

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

 

Please can someone let me know where I am going wrong?

 

Thank you

Share this post


Link to post
Share on other sites

If you are defining all the other states in this same way, you are resetting your ABC object to an empty object each time, removing thus everything that you had put in it before.

 

When defining the ABC object try this:

var ABC = ABC || {};

So if it's already been defined, it will keep it.

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.