Creating the default functions called by Phaser.
A Pen by Richard Davey on CodePen.
Creating the default functions called by Phaser.
A Pen by Richard Davey on CodePen.
<script src="http://s.cdpn.io/35162/phaser.js"></script> | |
<div id="game"></div> |
/* | |
Getting Started with Phaser - Part 3 | |
*/ | |
/* | |
After giving the game a size you can give it up to 3 extra parameters. | |
These control the functions called by the game when it is started. | |
init. This is where you load assets like images and sound or set-up basic game settings. | |
Init isn't used for creating game objects, it's just for getting things all set-up. When Phasers loader | |
finishes loading it will automatically call the create function, if one exists. | |
create. This is where you create everything your game will need such as sprites and tilemaps. You can also | |
configure the game world here. | |
update. Phaser maintains its own core game loop. After processing the game objects and other internal | |
properties it will call your update function. You don't have to have an update function, but nearly all games | |
will. In here is where you'd do things like move sprites, check for input, perform collision and more. | |
Note: This isn't the only way to set the game functions, and for more advanced games you can use Phasers state | |
management features, but for this guide (and to get up and running quickly) we'll use the above approach. | |
*/ | |
var myGame = new Phaser.Game(this, 'game', 600, 300, init, create update); | |
function init() { | |
// Because there is nothing in here the game just appears as a blank white object. | |
// Let's change that in Part 4 :) | |
} | |
function create() { | |
// Create is always called after init. | |
} | |
function update() { | |
// This is called every frame by the core game loop | |
} |