diff --git a/README.md b/README.md index a0b810900..054ea74a0 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ Try out 200+ [Phaser Examples](http://gametest.mobi/phaser/examples/) [Subscribe to our new Phaser Newsletter](https://confirmsubscription.com/h/r/369DE48E3E86AF1E). We'll email you when new versions are released as well as send you our regular Phaser game making magazine. +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/photonstorm/phaser/trend.png)](https://bitdeli.com/free "Bitdeli Badge") + Welcome to Phaser ----------------- diff --git a/examples/wip/text on top.js b/examples/wip/text on top.js new file mode 100644 index 000000000..8acd3b7bc --- /dev/null +++ b/examples/wip/text on top.js @@ -0,0 +1,61 @@ + +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'); + +} + +var cursors; +var group; +var text; +var timer; + +function create() { + + game.stage.backgroundColor = '#007236'; + + for (var i = 0; i < 200; i++) + { + game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom'); + } + + text = game.add.text(0, 0, "Text Above Sprites", { font: "64px Arial", fill: "#00bff3", align: "center" }); + + timer = new Phaser.Timer(game); + timer.add(1000); + + cursors = game.input.keyboard.createCursorKeys(); + +} + +function update() { + + timer.update(); + + if (cursors.up.isDown) + { + text.y -= 4; + } + else if (cursors.down.isDown) + { + text.y += 4; + } + + if (cursors.left.isDown) + { + text.x -= 4; + } + else if (cursors.right.isDown) + { + text.x += 4; + } + +} + +function render() { + + // game.debug.renderCameraInfo(game.camera, 32, 32); + +} diff --git a/src/time/Timer.js b/src/time/Timer.js index 3e65889eb..8723de8cc 100644 --- a/src/time/Timer.js +++ b/src/time/Timer.js @@ -55,6 +55,8 @@ Phaser.Timer.prototype = { this.events.push({ delay: delay, dispatched: false, + repeatCount: 0, + loop: false, args: Array.prototype.splice.call(arguments, 1) }); @@ -68,6 +70,29 @@ Phaser.Timer.prototype = { }, + repeat: function (delay, count) { + + this.events.push({ + delay: delay, + dispatched: false, + repeatCount: count, + loop: false, + args: Array.prototype.splice.call(arguments, 2) + }); + + }, + + loop: function (delay) { + + this.events.push({ + delay: delay, + dispatched: false, + loop: true, + args: Array.prototype.splice.call(arguments, 2) + }); + + }, + start: function() { this._started = this.game.time.now; @@ -100,10 +125,24 @@ Phaser.Timer.prototype = { { if (this.events[i].dispatched === false && seconds >= this.events[i].delay) { - this.events[i].dispatched = true; - // this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args); - this.onEvent.dispatch.apply(this, this.events[i].args); - // ought to slice it now + if (this.events[i].loop) + { + this.onEvent.dispatch.apply(this, this.events[i].args); + this.events[i].delay = seconds + this.events[i].delay; + } + else if (this.events[i].repeatCount > 0) + { + this.events[i].repeatCount--; + this.onEvent.dispatch.apply(this, this.events[i].args); + this.events[i].delay = seconds + this.events[i].delay; + } + else + { + this.events[i].dispatched = true; + // this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args); + this.onEvent.dispatch.apply(this, this.events[i].args); + // ought to slice it now + } } } }