Added the new Timer, TimerEvent and Time methods to the TypeScript definitions files.

This commit is contained in:
photonstorm
2014-01-13 14:18:15 +00:00
parent 35cef4e529
commit c6fa2cb7b6
5 changed files with 59 additions and 115 deletions
+2 -2
View File
@@ -104,12 +104,12 @@ New Examples:
* Particles - Rain by Jens Anders Bakke.
* Particles - Snow by Jens Anders Bakke.
* Groups - Nested Groups - showing how to embed one Group into another Group.
* Time - Lots of new examples showing how to use the Phaser.Timer class.
* Time - Lots of new examples showing how to use the updated Phaser.Timer class.
Updates:
* Updated to latest Pixi.js dev branch build.
* Updated to latest Pixi.js dev branch build (pre 1.4 release)
* When a Sprite is destroyed any active filters are removed at the same time.
* Updated Pixi.js so that removing filters now works correctly without breaking the display list.
* Phaser.Canvas.create updated so it can be given an ID as the 3rd parameter (can also be set via new Game configuration object).
+53 -3
View File
@@ -1327,15 +1327,65 @@ declare module Phaser {
pauseDuration: number;
timeToCall: number;
lastTime: number;
totalElapsedSeconds(): number;
update(time: number): number;
events: Phaser.Timer;
create(autoDestroy: boolean): Phaser.Timer;
removeAll(): void;
update(time: number): void;
gamePaused(): void;
gameResumed(): void;
totalElapsedSeconds(): number;
elapsedSince(since: number): number;
elapsedSecondsSince(since: number): number;
reset(): void;
}
class Timer {
constructor(game: Phaser.Game, autoDestroy: boolean);
game: Phaser.Game;
running: boolean;
autoDestroy: boolean;
expired: boolean;
events: Phaser.TimerEvent[];
onComplete: Phaser.Signal;
nextTick: number;
paused: boolean;
static MINUTE: number;
static SECOND: number;
static HALF: number;
static QUARTER: number;
create(delay: number, loop: boolean, repeatCount: number, callback: any, callbackContext: any, ...): Phaser.TimerEvent;
add(delay: number, callback: any, callbackContext: any, ...): Phaser.TimerEvent;
repeat(delay: number, repeatCount: number, callback: any, callbackContext: any, ...): Phaser.TimerEvent;
create(delay: number, loop: boolean, repeatCount: number, callback: any, callbackContext: any, ...): Phaser.TimerEvent;
loop(delay: number, callback: any, callbackContext: any, ...): Phaser.TimerEvent;
start(): void;
stop(): void;
remove(event: Phaser.TimerEvent): boolean;
order():void;
sortHandler():number;
update(time: number): boolean;
pause(): void;
resume(): void;
destroy(): void;
next: number;
duration: number;
length: number;
ms: number;
seconds: number;
}
class TimerEvent {
constructor(timer: Phaser.Timer, delay: number, tick: number, repeatCount: number, loop: boolean, callback: any, callbackContext, any, args:any[]);
timer: Phaser.Timer;
delay: number;
tick: number;
repeatCount: number;
loop: boolean;
callback: any;
callbackContext: any;
args: any[];
}
class AnimationManager {
constructor(sprite);
sprite: Phaser.Sprite;
@@ -1705,7 +1755,7 @@ declare module Phaser {
width: number;
height: number;
halfWidth: number;
helfHeight: number;
halfHeight: number;
velocity: Phaser.Point;
acceleration: Phaser.Point;
drag: Phaser.Point;
+2 -1
View File
@@ -33,7 +33,8 @@ function create() {
sprite.body.bounce.setTo(0.8, 0.8);
//sprite.body.drag.setTo(0, -20);
sprite.body.drag.setTo(10, 10);
// sprite.body.drag.setTo(10, 10);
sprite.body.friction = 0.1;
// sprite.body.sleepMin.setTo(-50, -20);
// sprite.body.sleepMax.setTo(50, 20);
-107
View File
@@ -161,54 +161,6 @@ Phaser.Physics.Arcade = function (game) {
Phaser.Physics.Arcade.prototype = {
/**
* Called automatically by a Physics body, it updates all motion related values on the Body.
*
* @method Phaser.Physics.Arcade#updateMotion
* @param {Phaser.Physics.Arcade.Body} The Body object to be updated.
updateMotion: function (body) {
// If you're wondering why the velocity is halved and applied twice, read this: http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html
// Rotation
this._velocityDelta = (this.computeVelocity(body, body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular, 0) - body.angularVelocity) * 0.5;
body.angularVelocity += this._velocityDelta;
body.rotation += (body.angularVelocity * this.game.time.physicsElapsed);
body.angularVelocity += this._velocityDelta;
if (body.allowGravity)
{
// Gravity was previously applied without taking physicsElapsed into account
// so it needs to be multiplied by 60 (fps) for compatibility with existing games
this._gravityX = (this.gravity.x + body.gravity.x) * 60;
this._gravityY = (this.gravity.y + body.gravity.y) * 60;
}
else
{
this._gravityX = 0;
this._gravityY = 0;
}
body.motionVelocity.x = (this.computeVelocity(body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x, this._gravityX) - body.velocity.x) * 0.5;
body.motionVelocity.y = (this.computeVelocity(body, body.velocity.y, body.acceleration.y, body.drag.y, body.maxVelocity.y, this._gravityY) - body.velocity.y) * 0.5;
// Horizontal
// this._velocityDelta = (this.computeVelocity(body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x, this._gravityX) - body.velocity.x) * 0.5;
// body.velocity.x += this._velocityDelta;
// body.x += (body.velocity.x * this.game.time.physicsElapsed);
// body.velocity.x += this._velocityDelta;
// Vertical
// this._velocityDelta = (this.computeVelocity(body, body.velocity.y, body.acceleration.y, body.drag.y, body.maxVelocity.y, this._gravityY) - body.velocity.y) * 0.5;
// body.motionVelocity.y = this._velocityDelta;
// body.velocity.y += this._velocityDelta;
// body.y += (body.velocity.y * this.game.time.physicsElapsed);
// body.velocity.y += this._velocityDelta;
},
*/
/**
* Called automatically by a Physics body, it updates all motion related values on the Body.
*
@@ -262,9 +214,6 @@ Phaser.Physics.Arcade.prototype = {
}
}
// velocity = velocity + gravity*delta_time/2
// position = position + velocity*delta_time
// velocity = velocity + gravity*delta_time/2
// temp = acc*dt
// pos = pos + dt*(vel + temp/2)
// vel = vel + temp
@@ -274,62 +223,6 @@ Phaser.Physics.Arcade.prototype = {
},
/**
* A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
*
* @method Phaser.Physics.Arcade#computeVelocity
* @param {Phaser.Physics.Arcade.Body} body - The Body object to be updated.
* @param {number} velocity - Any component of velocity (e.g. 20).
* @param {number} acceleration - Rate at which the velocity is changing.
* @param {number} drag - Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
* @param {number} [max=10000] - An absolute value cap for the velocity.
* @param {number} gravity - The acceleration due to gravity. Gravity will not induce drag.
* @return {number} The altered Velocity value.
computeVelocity: function (body, velocity, acceleration, drag, max, gravity) {
max = max || 10000;
// velocity = (acceleration + gravity) * this.game.time.physicsElapsed;
// velocity += (acceleration + gravity) * this.game.time.physicsElapsed;
velocity = (acceleration + gravity);
if (acceleration === 0 && drag !== 0)
{
this._drag = drag * this.game.time.physicsElapsed;
// this._drag = drag;
// if (velocity - drag > 0)
if (velocity - this._drag > 0)
{
// velocity += this._drag;
velocity -= drag;
}
// else if (velocity - drag < 0)
else if (velocity - this._drag < 0)
{
// velocity -= this._drag;
velocity -= drag;
}
else
{
velocity = 0;
}
}
if (velocity > max)
{
velocity = max;
}
else if (velocity < -max)
{
velocity = -max;
}
return velocity;
},
*/
/**
* Called automatically by the core game loop.
*
+2 -2
View File
@@ -455,9 +455,9 @@ Phaser.Utils.Debug.prototype = {
this.start(x, y, color, 220);
this.splitline('x: ' + sprite.body.x.toFixed(2), 'y: ' + sprite.body.y.toFixed(2), 'width: ' + sprite.width, 'height: ' + sprite.height);
this.splitline('speed: ' + sprite.body.speed.toFixed(2), 'angle: ' + sprite.body.angle.toFixed(2));
this.splitline('speed: ' + sprite.body.speed.toFixed(2), 'angle: ' + sprite.body.angle.toFixed(2), 'friction: ' + sprite.body.friction);
//this.splitline('old x: ' + sprite.body.preX.toFixed(2), 'y: ' + sprite.body.preY.toFixed(2));
this.splitline('drag x: ' + sprite.body.drag.x, 'y: ' + sprite.body.drag.y);
// this.splitline('drag x: ' + sprite.body.drag.x, 'y: ' + sprite.body.drag.y);
this.splitline('gravity x: ' + sprite.body.gravity.x, 'y: ' + sprite.body.gravity.y);
this.splitline('world gravity x: ' + this.game.physics.gravity.x, 'y: ' + this.game.physics.gravity.y);
this.splitline('acceleration x: ' + sprite.body.acceleration.x.toFixed(2), 'y: ' + sprite.body.acceleration.y.toFixed(2));