phaser/examples/wip/timer simple.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-01-04 02:53:32 +00:00
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
game.load.image('sonic', 'assets/sprites/pangball.png');
2014-01-04 02:53:32 +00:00
}
var timer;
function create() {
game.stage.backgroundColor = '#007236';
// Every second we will call the addSprite function. This will happen 10 times and then stop.
// The final parameter is the one that will be sent to the addSprite function and in this case is the sprite key.
game.time.repeatEvent(Phaser.Timer.SECOND, 10, addSprite, this, 'mushroom');
2014-01-04 02:53:32 +00:00
// Every 1.5 seconds we will call the addSprite function. This will happen 5 times and then stop.
game.time.repeatEvent(1500, 10, addSprite, this, 'sonic');
2014-01-04 02:53:32 +00:00
}
function addSprite(key) {
2014-01-04 02:53:32 +00:00
console.log(arguments);
game.add.sprite(game.world.randomX, game.world.randomY, key);
2014-01-04 02:53:32 +00:00
}
function update() {
}
function render() {
game.debug.renderText(game.time._timer.ms, 32, 32);
2014-01-04 02:53:32 +00:00
// game.debug.renderCameraInfo(game.camera, 32, 32);
}