Added BitDeli badge, also updating Timer class.

This commit is contained in:
photonstorm 2014-01-03 12:43:58 +00:00
parent c3183dcea9
commit 7aa45b5872
3 changed files with 106 additions and 4 deletions

View file

@ -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
-----------------

View file

@ -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);
}

View file

@ -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
}
}
}
}