forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicitly paused Timer continues if you un-focus and focus the brows…
…er window. Added TimerEvent.pendingDelete and checks in Timer.update, so that removing an event in a callback no longer throws an exception.
- Loading branch information
1 parent
eddce65
commit 68d5c73
Showing
4 changed files
with
64 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,53 @@ | ||
|
||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); | ||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); | ||
|
||
function preload() { | ||
|
||
game.load.image('mushroom', 'assets/sprites/mushroom2.png'); | ||
game.load.image('sonic', 'assets/sprites/pangball.png'); | ||
game.load.image('ball', 'assets/sprites/pangball.png'); | ||
|
||
} | ||
|
||
var timer; | ||
var t; | ||
|
||
function create() { | ||
|
||
game.stage.backgroundColor = '#007236'; | ||
game.stage.backgroundColor = '#6688ee'; | ||
|
||
t = game.time.create(false); | ||
|
||
t.repeat(Phaser.Timer.SECOND * 2, 10, createBall, this); | ||
t.repeat(Phaser.Timer.SECOND * 3, 10, createBall, this); | ||
|
||
// 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'); | ||
t.start(); | ||
|
||
// 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'); | ||
game.input.onDown.add(killThem, this); | ||
|
||
} | ||
|
||
function addSprite(key) { | ||
function createBall() { | ||
|
||
console.log(arguments); | ||
// 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(); | ||
|
||
game.add.sprite(game.world.randomX, game.world.randomY, key); | ||
|
||
} | ||
|
||
function update() { | ||
function killThem() { | ||
|
||
|
||
} | ||
|
||
function render() { | ||
|
||
game.debug.renderText(game.time._timer.ms, 32, 32); | ||
// game.debug.renderCameraInfo(game.camera, 32, 32); | ||
game.debug.renderText("Time until event: " + t.duration.toFixed(0), 32, 32); | ||
game.debug.renderText("Next tick: " + t.next.toFixed(0), 32, 64); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters