Added new Contributors guide.

This commit is contained in:
photonstorm
2014-01-08 01:53:28 +00:00
parent 038bca11b2
commit 67e2caafbc
5 changed files with 169 additions and 47 deletions
+7 -3
View File
@@ -828,12 +828,16 @@ Phaser.Physics.Arcade.prototype = {
* @returns {boolean} Returns true if the bodies were separated, otherwise false.
*/
separate: function (body1, body2) {
if(body1 !== body2)
if (body1 !== body2)
{
this._result = (this.separateX(body1, body2) || this.separateY(body1, body2));
} else {
}
else
{
this._result = false;
}
},
/**
@@ -1037,7 +1041,7 @@ Phaser.Physics.Arcade.prototype = {
}
else if (!body1.immovable)
{
body1.y = body1.y - this._overlap;
body1.y -= this._overlap;
body1.velocity.y = this._velocity2 - this._velocity1 * body1.bounce.y;
// This is special case code that handles things like horizontal moving platforms you can ride
+5 -1
View File
@@ -108,6 +108,8 @@ Phaser.Time = function (game) {
*/
this.lastTime = 0;
this._timer = new Phaser.Timer(this.game, 1, false);
// Listen for game pause/resume events
this.game.onPause.add(this.gamePaused, this);
this.game.onResume.add(this.gameResumed, this);
@@ -128,8 +130,10 @@ Phaser.Time = function (game) {
Phaser.Time.prototype = {
/**
* Creates a new Phaser.Timer object.
* Creates a new stand-alone Phaser.Timer object.
* @method Phaser.Time#create
* @param {number} [timeUnit=1000] - The number of ms that represent 1 unit of time. For example a timer that ticks every second would have a timeUnit value of 1000.
* @param {boolean} [autoDestroy=true] - A Timer that is set to automatically destroy itself will do so after all of its events have been dispatched (assuming no looping events).
+75 -35
View File
@@ -6,19 +6,17 @@
/**
* A Timer is a way to create small re-usable or disposable objects that do nothing but wait for a specific moment in time, and then dispatch an event.
* You can add as many events to a Timer as you like, each with their own delays. A Timer uses its own timeUnit, which directly correlates to milliseconds.
* For example a Timer with a timeUnit of 250 would fire an event every quarter of a second.
* You can add as many events to a Timer as you like, each with their own delays. A Timer uses milliseconds as its unit of time. There are 1000 ms in 1 second.
* So if you want to fire an event every quarter of a second you'd need to set the delay to 250.
*
* @class Phaser.Timer
* @classdesc A Timer is a way to create small re-usable or disposable objects that do nothing but wait for a specific moment in time, and then dispatch an event.
* @constructor
* @param {Phaser.Game} game A reference to the currently running game.
* @param {number} [timeUnit=1000] - The number of ms that represent 1 unit of time. For example a timer that ticks every second would have a timeUnit value of 1000.
* @param {boolean} [autoDestroy=true] - A Timer that is set to automatically destroy itself will do so after all of its events have been dispatched (assuming no looping events).
*/
Phaser.Timer = function (game, timeUnit, autoDestroy) {
Phaser.Timer = function (game, autoDestroy) {
if (typeof timeUnit === 'undefined') { timeUnit = Phaser.Timer.SECOND; }
if (typeof autoDestroy === 'undefined') { autoDestroy = true; }
/**
@@ -69,9 +67,16 @@ Phaser.Timer = function (game, timeUnit, autoDestroy) {
this.onEvent = new Phaser.Signal();
/**
* @property {number} timeUnit - The unit of time being used by this Timer.
* @property {number} nextTick - The time the next tick will occur. Do not set this value directly.
* @protected
*/
this.timeUnit = timeUnit;
this.nextTick = 0;
/**
* @property {number} _now - The current start-time adjusted time.
* @protected
*/
this._now = 0;
};
@@ -106,57 +111,60 @@ Phaser.Timer.prototype = {
* @method Phaser.Timer#_create
* @private
*/
_create: function (delay, loop, repeatCount, args) {
create: function (delay, loop, repeatCount, args) {
this.events.push({
delay: delay,
tick: delay,
expired: false,
repeatCount: repeatCount,
loop: loop,
args: args
});
this.order();
this.expired = false;
},
// Need to do a Stop Watch example
/**
* Adds a new Event to this Timer. The event will fire after the given amount of 'delay' has passed if the Timer is running.
* Call Timer.start() once you have added all of the Events you require for this Timer.
* Adds a new Event to this Timer. The event will fire after the given amount of 'delay' in milliseconds has passed, once the Timer has started running.
* Call Timer.start() once you have added all of the Events you require for this Timer. The delay is in relation to when the Timer starts, not the time it was added.
* @method Phaser.Timer#add
* @param {number} [delay] - The number of timeUnits before the Timer will dispatch its onEvent signal.
* @param {number} [delay] - The number of milliseconds before the Timer will dispatch its onEvent signal.
*/
add: function (delay) {
this._create(delay, false, 0, Array.prototype.splice.call(arguments, 1));
this.create(delay, false, 0, Array.prototype.splice.call(arguments, 1));
},
/**
* Adds a new Event to this Timer that will repeat for the given number of iterations.
* The event will fire after the given amount of 'delay' has passed if the Timer is running.
* Call Timer.start() once you have added all of the Events you require for this Timer.
* The event will fire after the given amount of 'delay' milliseconds has passed once the Timer has started running.
* Call Timer.start() once you have added all of the Events you require for this Timer. The delay is in relation to when the Timer starts, not the time it was added.
* @method Phaser.Timer#repeat
* @param {number} [delay] - The number of timeUnits before the Timer will dispatch its onEvent signal.
* @param {number} [delay] - The number of milliseconds before the Timer will dispatch its onEvent signal.
* @param {number} [count] - The number of times to repeat this Event.
*/
repeat: function (delay, count) {
this._create(delay, false, count, Array.prototype.splice.call(arguments, 2));
this.create(delay, false, count, Array.prototype.splice.call(arguments, 2));
},
/**
* Adds a new looped Event to this Timer that will repeat forever or until the Timer is stopped.
* The event will fire after the given amount of 'delay' has passed if the Timer is running.
* Call Timer.start() once you have added all of the Events you require for this Timer.
* The event will fire after the given amount of 'delay' milliseconds has passed once the Timer has started running.
* Call Timer.start() once you have added all of the Events you require for this Timer. The delay is in relation to when the Timer starts, not the time it was added.
* @method Phaser.Timer#loop
* @param {number} [delay] - The number of timeUnits before the Timer will dispatch its onEvent signal.
* @param {number} [delay] - The number of milliseconds before the Timer will dispatch its onEvent signal.
*/
loop: function (delay) {
this._create(delay, true, 0, Array.prototype.splice.call(arguments, 1));
this.create(delay, true, 0, Array.prototype.splice.call(arguments, 1));
},
@@ -182,8 +190,32 @@ Phaser.Timer.prototype = {
},
order: function () {
// Sort the events so the one with the lowest tick is first
this.events.sort(this.sortHandler);
this.nextTick = this.events[0].tick;
},
sortHandler: function (a, b) {
if (a.tick < b.tick)
{
return -1;
}
else if (a.tick > b.tick)
{
return 1;
}
return 0;
},
/**
* The main Timer update event.
* The main Timer update event, called automatically by the Game clock.
* @method Phaser.Timer#update
* @protected
* @param {number} time - The time from the core game clock.
@@ -191,44 +223,52 @@ Phaser.Timer.prototype = {
*/
update: function(time) {
if (this.running)
{
var now = (time - this._started) / this.timeUnit;
var expired = 0;
this._now = time - this._started;
for (var i = 0, len = this.events.length; i < len; i++)
if (this.running && this._now >= this.nextTick)
{
var i = 0;
var len = this.events.length;
while (i < len)
{
if (this.events[i].expired === false && now >= this.events[i].tick)
if (this._now >= this.events[i].tick)
{
if (this.events[i].loop)
{
this.events[i].tick += this.events[i].delay - (now - this.events[i].tick);
this.events[i].tick += this.events[i].delay - (this._now - this.events[i].tick);
this.onEvent.dispatch.apply(this, this.events[i].args);
}
else if (this.events[i].repeatCount > 0)
{
this.events[i].repeatCount--;
this.events[i].tick += this.events[i].delay - (now - this.events[i].tick);
this.events[i].tick += this.events[i].delay - (this._now - this.events[i].tick);
this.onEvent.dispatch.apply(this, this.events[i].args);
}
else
{
this.events[i].expired = true;
this.onEvent.dispatch.apply(this, this.events[i].args);
this.events.splice(i, 1);
len--;
}
}
if (this.events[i].expired)
i++;
}
else
{
expired++;
break;
}
}
// There are no events left at all
if (expired === this.events.length)
if (this.events.length > 0)
{
this.expired = true;
}
else
{
this.order();
}
}
if (this.expired && this.autoDestroy)