Jump to content

help with phaser engine, render, update etc.


Recommended Posts

Hello Forum

I have started to creating a game with phaser.io . I followed the tutorial from lessmilk. Now I have a basic question. 

In the tutorial he use this method: 

// Create our 'main' state that will contain the game
var mainState = {
    preload: function() { 
        // This function will be executed at the beginning     
        // That's where we load the images and sounds 

    create: function() { 
        // This function is called after the preload function     
        // Here we set up the game, display sprites, etc.  

    update: function() {
        // This function is called 60 times per second    
        // It contains the game's logic   

// Initialize Phaser, and create a 400px by 490px game
var game = new Phaser.Game(400, 490);

// Add the 'mainState' and call it 'main'
game.state.add('main', mainState); 

// Start the state to actually start the game

But I also see in other projects or examples like in the phaser.io examples something like this:

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

function preload() {


function create() {


function render() {



Now I want to know what I should take or learn better. I think the first one is an older version of phaser.io? Is there some issues with the old one, what is better? Or can I make it like I want at the end?

Thank you.

Link to comment
Share on other sites

The difference of the two examples is that the first examples uses states and the second one does not use states.

If you only have one state it does not really matter wich example you chose, but when you add multiple states you will need the first example. You can then create multiple states (for example one for the menu and two levels).

This makes it also very easy to break up the code into multiple files, so that you have a seperate file for every state.


Link to comment
Share on other sites


  • Recently Browsing   0 members

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