mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 05:03:37 +00:00
Added BitDeli badge, also updating Timer class.
This commit is contained in:
parent
c3183dcea9
commit
7aa45b5872
3 changed files with 106 additions and 4 deletions
|
@ -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
|
||||
-----------------
|
||||
|
|
61
examples/wip/text on top.js
Normal file
61
examples/wip/text on top.js
Normal 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);
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
@ -99,6 +124,19 @@ Phaser.Timer.prototype = {
|
|||
for (var i = 0, len = this.events.length; i < len; i++)
|
||||
{
|
||||
if (this.events[i].dispatched === false && seconds >= this.events[i].delay)
|
||||
{
|
||||
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);
|
||||
|
@ -107,6 +145,7 @@ Phaser.Timer.prototype = {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue