Gamedev Phaser Workshop - lesson 03
Load the assets and print them on screen
by Ivan Enzhaev
HTML
<script src="https://end3r.github.io/Gamedev-Phaser-Content-Kit/demos/js/phaser.2.4.2.min.js"></script>
CSS
* { padding: 0; margin: 0; }
JavaScript
var game = new Phaser.Game(480, 320, Phaser.AUTO, null, {preload: preload, create: create, update: update});
var ball;
function preload() {
handleRemoteImagesOnJSFiddle();
game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
game.scale.pageAlignHorizontally = true;
game.scale.pageAlignVertically = true;
game.stage.backgroundColor = '#eee';
game.load.image('ball', 'img/ball.png');
}
function create() {
ball = game.add.sprite(50, 50, 'ball');
}
function update() {}
// this function (needed only on JSFiddle) take care of loading the images from the remote server
function handleRemoteImagesOnJSFiddle() {
game.load.baseURL = 'https://end3r.github.io/Gamedev-Phaser-Content-Kit/demos/';
game.load.crossOrigin = 'anonymous';
}