Skip to content

Commit c6fa2cb

Browse files
committed
Added the new Timer, TimerEvent and Time methods to the TypeScript definitions files.
1 parent 35cef4e commit c6fa2cb

5 files changed

Lines changed: 59 additions & 115 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ New Examples:
104104
* Particles - Rain by Jens Anders Bakke.
105105
* Particles - Snow by Jens Anders Bakke.
106106
* Groups - Nested Groups - showing how to embed one Group into another Group.
107-
* Time - Lots of new examples showing how to use the Phaser.Timer class.
107+
* Time - Lots of new examples showing how to use the updated Phaser.Timer class.
108108

109109

110110
Updates:
111111

112-
* Updated to latest Pixi.js dev branch build.
112+
* Updated to latest Pixi.js dev branch build (pre 1.4 release)
113113
* When a Sprite is destroyed any active filters are removed at the same time.
114114
* Updated Pixi.js so that removing filters now works correctly without breaking the display list.
115115
* Phaser.Canvas.create updated so it can be given an ID as the 3rd parameter (can also be set via new Game configuration object).

build/phaser.d.ts

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,15 +1327,65 @@ declare module Phaser {
13271327
pauseDuration: number;
13281328
timeToCall: number;
13291329
lastTime: number;
1330-
totalElapsedSeconds(): number;
1331-
update(time: number): number;
1330+
events: Phaser.Timer;
1331+
create(autoDestroy: boolean): Phaser.Timer;
1332+
removeAll(): void;
1333+
update(time: number): void;
13321334
gamePaused(): void;
13331335
gameResumed(): void;
1336+
totalElapsedSeconds(): number;
13341337
elapsedSince(since: number): number;
13351338
elapsedSecondsSince(since: number): number;
13361339
reset(): void;
13371340
}
13381341

1342+
class Timer {
1343+
constructor(game: Phaser.Game, autoDestroy: boolean);
1344+
game: Phaser.Game;
1345+
running: boolean;
1346+
autoDestroy: boolean;
1347+
expired: boolean;
1348+
events: Phaser.TimerEvent[];
1349+
onComplete: Phaser.Signal;
1350+
nextTick: number;
1351+
paused: boolean;
1352+
static MINUTE: number;
1353+
static SECOND: number;
1354+
static HALF: number;
1355+
static QUARTER: number;
1356+
create(delay: number, loop: boolean, repeatCount: number, callback: any, callbackContext: any, ...): Phaser.TimerEvent;
1357+
add(delay: number, callback: any, callbackContext: any, ...): Phaser.TimerEvent;
1358+
repeat(delay: number, repeatCount: number, callback: any, callbackContext: any, ...): Phaser.TimerEvent;
1359+
create(delay: number, loop: boolean, repeatCount: number, callback: any, callbackContext: any, ...): Phaser.TimerEvent;
1360+
loop(delay: number, callback: any, callbackContext: any, ...): Phaser.TimerEvent;
1361+
start(): void;
1362+
stop(): void;
1363+
remove(event: Phaser.TimerEvent): boolean;
1364+
order():void;
1365+
sortHandler():number;
1366+
update(time: number): boolean;
1367+
pause(): void;
1368+
resume(): void;
1369+
destroy(): void;
1370+
next: number;
1371+
duration: number;
1372+
length: number;
1373+
ms: number;
1374+
seconds: number;
1375+
}
1376+
1377+
class TimerEvent {
1378+
constructor(timer: Phaser.Timer, delay: number, tick: number, repeatCount: number, loop: boolean, callback: any, callbackContext, any, args:any[]);
1379+
timer: Phaser.Timer;
1380+
delay: number;
1381+
tick: number;
1382+
repeatCount: number;
1383+
loop: boolean;
1384+
callback: any;
1385+
callbackContext: any;
1386+
args: any[];
1387+
}
1388+
13391389
class AnimationManager {
13401390
constructor(sprite);
13411391
sprite: Phaser.Sprite;
@@ -1705,7 +1755,7 @@ declare module Phaser {
17051755
width: number;
17061756
height: number;
17071757
halfWidth: number;
1708-
helfHeight: number;
1758+
halfHeight: number;
17091759
velocity: Phaser.Point;
17101760
acceleration: Phaser.Point;
17111761
drag: Phaser.Point;

examples/wip/physics-motion.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function create() {
3333
sprite.body.bounce.setTo(0.8, 0.8);
3434

3535
//sprite.body.drag.setTo(0, -20);
36-
sprite.body.drag.setTo(10, 10);
36+
// sprite.body.drag.setTo(10, 10);
37+
sprite.body.friction = 0.1;
3738

3839
// sprite.body.sleepMin.setTo(-50, -20);
3940
// sprite.body.sleepMax.setTo(50, 20);

src/physics/arcade/ArcadePhysics.js

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -161,54 +161,6 @@ Phaser.Physics.Arcade = function (game) {
161161

162162
Phaser.Physics.Arcade.prototype = {
163163

164-
/**
165-
* Called automatically by a Physics body, it updates all motion related values on the Body.
166-
*
167-
* @method Phaser.Physics.Arcade#updateMotion
168-
* @param {Phaser.Physics.Arcade.Body} The Body object to be updated.
169-
updateMotion: function (body) {
170-
171-
// If you're wondering why the velocity is halved and applied twice, read this: http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html
172-
173-
// Rotation
174-
this._velocityDelta = (this.computeVelocity(body, body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular, 0) - body.angularVelocity) * 0.5;
175-
body.angularVelocity += this._velocityDelta;
176-
body.rotation += (body.angularVelocity * this.game.time.physicsElapsed);
177-
body.angularVelocity += this._velocityDelta;
178-
179-
if (body.allowGravity)
180-
{
181-
// Gravity was previously applied without taking physicsElapsed into account
182-
// so it needs to be multiplied by 60 (fps) for compatibility with existing games
183-
this._gravityX = (this.gravity.x + body.gravity.x) * 60;
184-
this._gravityY = (this.gravity.y + body.gravity.y) * 60;
185-
}
186-
else
187-
{
188-
this._gravityX = 0;
189-
this._gravityY = 0;
190-
}
191-
192-
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;
193-
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;
194-
195-
// Horizontal
196-
// this._velocityDelta = (this.computeVelocity(body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x, this._gravityX) - body.velocity.x) * 0.5;
197-
// body.velocity.x += this._velocityDelta;
198-
// body.x += (body.velocity.x * this.game.time.physicsElapsed);
199-
// body.velocity.x += this._velocityDelta;
200-
201-
// Vertical
202-
// this._velocityDelta = (this.computeVelocity(body, body.velocity.y, body.acceleration.y, body.drag.y, body.maxVelocity.y, this._gravityY) - body.velocity.y) * 0.5;
203-
// body.motionVelocity.y = this._velocityDelta;
204-
205-
// body.velocity.y += this._velocityDelta;
206-
// body.y += (body.velocity.y * this.game.time.physicsElapsed);
207-
// body.velocity.y += this._velocityDelta;
208-
209-
},
210-
*/
211-
212164
/**
213165
* Called automatically by a Physics body, it updates all motion related values on the Body.
214166
*
@@ -262,9 +214,6 @@ Phaser.Physics.Arcade.prototype = {
262214
}
263215
}
264216

265-
// velocity = velocity + gravity*delta_time/2
266-
// position = position + velocity*delta_time
267-
// velocity = velocity + gravity*delta_time/2
268217
// temp = acc*dt
269218
// pos = pos + dt*(vel + temp/2)
270219
// vel = vel + temp
@@ -274,62 +223,6 @@ Phaser.Physics.Arcade.prototype = {
274223

275224
},
276225

277-
/**
278-
* A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
279-
*
280-
* @method Phaser.Physics.Arcade#computeVelocity
281-
* @param {Phaser.Physics.Arcade.Body} body - The Body object to be updated.
282-
* @param {number} velocity - Any component of velocity (e.g. 20).
283-
* @param {number} acceleration - Rate at which the velocity is changing.
284-
* @param {number} drag - Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
285-
* @param {number} [max=10000] - An absolute value cap for the velocity.
286-
* @param {number} gravity - The acceleration due to gravity. Gravity will not induce drag.
287-
* @return {number} The altered Velocity value.
288-
computeVelocity: function (body, velocity, acceleration, drag, max, gravity) {
289-
290-
max = max || 10000;
291-
292-
// velocity = (acceleration + gravity) * this.game.time.physicsElapsed;
293-
// velocity += (acceleration + gravity) * this.game.time.physicsElapsed;
294-
velocity = (acceleration + gravity);
295-
296-
if (acceleration === 0 && drag !== 0)
297-
{
298-
this._drag = drag * this.game.time.physicsElapsed;
299-
// this._drag = drag;
300-
301-
// if (velocity - drag > 0)
302-
if (velocity - this._drag > 0)
303-
{
304-
// velocity += this._drag;
305-
velocity -= drag;
306-
}
307-
// else if (velocity - drag < 0)
308-
else if (velocity - this._drag < 0)
309-
{
310-
// velocity -= this._drag;
311-
velocity -= drag;
312-
}
313-
else
314-
{
315-
velocity = 0;
316-
}
317-
}
318-
319-
if (velocity > max)
320-
{
321-
velocity = max;
322-
}
323-
else if (velocity < -max)
324-
{
325-
velocity = -max;
326-
}
327-
328-
return velocity;
329-
330-
},
331-
*/
332-
333226
/**
334227
* Called automatically by the core game loop.
335228
*

src/utils/Debug.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ Phaser.Utils.Debug.prototype = {
455455
this.start(x, y, color, 220);
456456

457457
this.splitline('x: ' + sprite.body.x.toFixed(2), 'y: ' + sprite.body.y.toFixed(2), 'width: ' + sprite.width, 'height: ' + sprite.height);
458-
this.splitline('speed: ' + sprite.body.speed.toFixed(2), 'angle: ' + sprite.body.angle.toFixed(2));
458+
this.splitline('speed: ' + sprite.body.speed.toFixed(2), 'angle: ' + sprite.body.angle.toFixed(2), 'friction: ' + sprite.body.friction);
459459
//this.splitline('old x: ' + sprite.body.preX.toFixed(2), 'y: ' + sprite.body.preY.toFixed(2));
460-
this.splitline('drag x: ' + sprite.body.drag.x, 'y: ' + sprite.body.drag.y);
460+
// this.splitline('drag x: ' + sprite.body.drag.x, 'y: ' + sprite.body.drag.y);
461461
this.splitline('gravity x: ' + sprite.body.gravity.x, 'y: ' + sprite.body.gravity.y);
462462
this.splitline('world gravity x: ' + this.game.physics.gravity.x, 'y: ' + this.game.physics.gravity.y);
463463
this.splitline('acceleration x: ' + sprite.body.acceleration.x.toFixed(2), 'y: ' + sprite.body.acceleration.y.toFixed(2));

0 commit comments

Comments
 (0)