Skip to content

Commit 7aa45b5

Browse files
committed
Added BitDeli badge, also updating Timer class.
1 parent c3183dc commit 7aa45b5

3 files changed

Lines changed: 106 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Try out 200+ [Phaser Examples](http://gametest.mobi/phaser/examples/)
1616

1717
[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.
1818

19+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/photonstorm/phaser/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
20+
1921

2022
Welcome to Phaser
2123
-----------------

examples/wip/text on top.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render : render });
3+
4+
function preload() {
5+
6+
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
7+
8+
}
9+
10+
var cursors;
11+
var group;
12+
var text;
13+
var timer;
14+
15+
function create() {
16+
17+
game.stage.backgroundColor = '#007236';
18+
19+
for (var i = 0; i < 200; i++)
20+
{
21+
game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
22+
}
23+
24+
text = game.add.text(0, 0, "Text Above Sprites", { font: "64px Arial", fill: "#00bff3", align: "center" });
25+
26+
timer = new Phaser.Timer(game);
27+
timer.add(1000);
28+
29+
cursors = game.input.keyboard.createCursorKeys();
30+
31+
}
32+
33+
function update() {
34+
35+
timer.update();
36+
37+
if (cursors.up.isDown)
38+
{
39+
text.y -= 4;
40+
}
41+
else if (cursors.down.isDown)
42+
{
43+
text.y += 4;
44+
}
45+
46+
if (cursors.left.isDown)
47+
{
48+
text.x -= 4;
49+
}
50+
else if (cursors.right.isDown)
51+
{
52+
text.x += 4;
53+
}
54+
55+
}
56+
57+
function render() {
58+
59+
// game.debug.renderCameraInfo(game.camera, 32, 32);
60+
61+
}

src/time/Timer.js

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Phaser.Timer.prototype = {
5555
this.events.push({
5656
delay: delay,
5757
dispatched: false,
58+
repeatCount: 0,
59+
loop: false,
5860
args: Array.prototype.splice.call(arguments, 1)
5961
});
6062

@@ -68,6 +70,29 @@ Phaser.Timer.prototype = {
6870

6971
},
7072

73+
repeat: function (delay, count) {
74+
75+
this.events.push({
76+
delay: delay,
77+
dispatched: false,
78+
repeatCount: count,
79+
loop: false,
80+
args: Array.prototype.splice.call(arguments, 2)
81+
});
82+
83+
},
84+
85+
loop: function (delay) {
86+
87+
this.events.push({
88+
delay: delay,
89+
dispatched: false,
90+
loop: true,
91+
args: Array.prototype.splice.call(arguments, 2)
92+
});
93+
94+
},
95+
7196
start: function() {
7297

7398
this._started = this.game.time.now;
@@ -100,10 +125,24 @@ Phaser.Timer.prototype = {
100125
{
101126
if (this.events[i].dispatched === false && seconds >= this.events[i].delay)
102127
{
103-
this.events[i].dispatched = true;
104-
// this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args);
105-
this.onEvent.dispatch.apply(this, this.events[i].args);
106-
// ought to slice it now
128+
if (this.events[i].loop)
129+
{
130+
this.onEvent.dispatch.apply(this, this.events[i].args);
131+
this.events[i].delay = seconds + this.events[i].delay;
132+
}
133+
else if (this.events[i].repeatCount > 0)
134+
{
135+
this.events[i].repeatCount--;
136+
this.onEvent.dispatch.apply(this, this.events[i].args);
137+
this.events[i].delay = seconds + this.events[i].delay;
138+
}
139+
else
140+
{
141+
this.events[i].dispatched = true;
142+
// this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args);
143+
this.onEvent.dispatch.apply(this, this.events[i].args);
144+
// ought to slice it now
145+
}
107146
}
108147
}
109148
}

0 commit comments

Comments
 (0)