hakura88 Posted August 4, 2016 Share Posted August 4, 2016 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 game.state.start('main'); 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 More sharing options...
P4UL Posted August 4, 2016 Share Posted August 4, 2016 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. hakura88 and drhayes 2 Link to comment Share on other sites More sharing options...
hakura88 Posted August 5, 2016 Author Share Posted August 5, 2016 okay thank you Link to comment Share on other sites More sharing options...
Recommended Posts