I'm quite new to Phaser and JavaScript really confused about state management.

Phaser has lots of documentation and info on the net, but everyone seems to be doing it a different way.

An example:

var game = new Phaser.Game(800,600, Phaser.AUTO, 'phaser-demo',
        {preload: preload, create: create, update: update, render: render});

function preload(){ ... }
function create() { ... }
function update() { ... }
function render() { ... }


window.game = new Phaser.Game(800, 600, Phaser.AUTO);
// all other states are in different files

module.exports = {
    preload: function(){ ... },
    create:  function(){ ... },
    update:  function(){ ... }

I would be grateful for a simple overview of properly handling states.

  • 1
    \$\begingroup\$ What's wrong with how you're doing things now? What have you tried and what's not working about it? \$\endgroup\$
    – House
    Mar 5, 2015 at 18:20
  • \$\begingroup\$ Im just confused because I often run into problems and I believe knowing the right way of doing it would make my development smoother. \$\endgroup\$ Mar 5, 2015 at 18:31
  • \$\begingroup\$ Right, but you need to be a bit more specific about your concerns. "What's the best way" will get you 5 different answers from 5 different people, without one being more correct than the next. Those aren't the types of questions we do here. \$\endgroup\$
    – House
    Mar 5, 2015 at 18:32
  • \$\begingroup\$ thanks! Ill rephrase my question to be more precise and understandable. \$\endgroup\$ Mar 5, 2015 at 18:33
  • 1
    \$\begingroup\$ Phaser has a State class you can use to build your own states. The whole initialization of phaser then boils down to adding states and starting with one. Maybe this tutorial helps. \$\endgroup\$
    – bummzack
    Mar 5, 2015 at 19:33


Browse other questions tagged .