phaser/examples/wip/misc/timer simple.js

54 lines
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, render: render });
2014-01-04 02:53:32 +00:00
function preload() {
game.load.image('ball', 'assets/sprites/pangball.png');
2014-01-04 02:53:32 +00:00
}
var t;
2014-01-04 02:53:32 +00:00
function create() {
game.stage.backgroundColor = '#6688ee';
2014-01-04 02:53:32 +00:00
t = game.time.create(false);
t.repeat(Phaser.Timer.SECOND * 2, 10, createBall, this);
t.repeat(Phaser.Timer.SECOND * 3, 10, createBall, this);
t.start();
2014-01-04 02:53:32 +00:00
game.input.onDown.add(killThem, this);
2014-01-04 02:53:32 +00:00
}
function createBall() {
2014-01-04 02:53:32 +00:00
// A bouncey ball sprite just to visually see what's going on.
var ball = game.add.sprite(game.world.randomX, 0, 'ball');
ball.body.gravity.y = 200;
ball.body.bounce.y = 0.5;
ball.body.collideWorldBounds = true;
console.log('nuked');
game.time.removeAll();
// t.removeAll();
2014-01-04 02:53:32 +00:00
}
function killThem() {
2014-01-04 02:53:32 +00:00
}
function render() {
game.debug.renderText("Time until event: " + t.duration.toFixed(0), 32, 32);
game.debug.renderText("Next tick: " + t.next.toFixed(0), 32, 64);
2014-01-04 02:53:32 +00:00
}