Skip to content

Commit dbdb2a2

Browse files
committed
Adjusted delta timer cap and fixed some typos and more examples.
1 parent 4432d37 commit dbdb2a2

10 files changed

Lines changed: 106 additions & 76 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ Updates:
169169
* Removed ArcadePhysics.preUpdate and postUpdate as neither are needed any more.
170170
* Body.bottom and Body.right are no longer rounded, so will give accurate sub-pixel values.
171171
* Fixed lots of documentation in the Emitter class.
172+
* The delta timer value used for physics calculations has had its cap limit modified from 1.0 to 0.05 in line with the core updates.
172173

173174

174175
Bug Fixes:

examples/collision/group vs self.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ function create() {
2828
sprites.setAll('body.collideWorldBounds', true);
2929
sprites.setAll('body.bounce.x', 1);
3030
sprites.setAll('body.bounce.y', 1);
31-
sprites.setAll('body.friction', 0);
3231
sprites.setAll('body.minBounceVelocity', 0);
3332

3433
}

examples/display/render texture starfield.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });
33

44
function preload() {
55

examples/games/matching pairs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:
66
function preload() {
77

88
game.load.tilemap('matching', 'assets/maps/phaser_tiles.json', null, Phaser.Tilemap.TILED_JSON);
9-
game.load.tileset('tiles', 'assets/tiles/phaser_tiles.png', 100, 100, -1, 1, 1);
9+
game.load.image('tiles', 'assets/tiles/phaser_tiles.png');
1010

1111
}
1212

@@ -41,9 +41,9 @@ function create() {
4141

4242
map = game.add.tilemap('matching');
4343

44-
tileset = game.add.tileset('tiles');
44+
// tileset = game.add.tileset('tiles');
4545

46-
layer = game.add.tilemapLayer(0, 0, 600, 600, tileset, map, 0);
46+
// layer = game.add.tilemapLayer(0, 0, 600, 600, tileset, map, 0);
4747

4848
marker = game.add.graphics();
4949
marker.lineStyle(2, 0x00FF00, 1);

examples/physics/mass velocity test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,25 @@ function create() {
2121
s.name = 'alien' + s;
2222
s.body.collideWorldBounds = true;
2323
s.body.bounce.setTo(0.8, 0.8);
24+
s.body.friction = 0;
25+
s.body.minVelocity.setTo(0, 0);
2426
s.body.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40);
2527
}
2628

2729
car = game.add.sprite(400, 300, 'car');
2830
car.anchor.setTo(0.5, 0.5);
2931
car.body.collideWorldBounds = true;
30-
car.body.bounce.setTo(0.8, 0.8);
32+
// car.body.bounce.setTo(0.8, 0.8);
3133
car.body.allowRotation = true;
34+
// car.body.immovable = true;
35+
// car.body.minBounceVelocity = 0;
3236

3337
}
3438

3539
function update() {
3640

41+
game.physics.collide(car, aliens);
42+
3743
car.body.velocity.x = 0;
3844
car.body.velocity.y = 0;
3945
car.body.angularVelocity = 0;
@@ -52,12 +58,10 @@ function update() {
5258
car.body.velocity.copyFrom(game.physics.velocityFromAngle(car.angle, 300));
5359
}
5460

55-
game.physics.collide(car, aliens);
56-
5761
}
5862

5963
function render() {
6064

61-
game.debug.renderSpriteInfo(car, 32, 32);
65+
game.debug.renderBodyInfo(car, 16, 24);
6266

6367
}

examples/wip/platform.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function create() {
3434

3535
balls = game.add.group();
3636

37-
for (var i = 0; i < 50; i++)
37+
for (var i = 0; i < 30; i++)
3838
{
3939
var s = balls.create(game.rnd.integerInRange(100, 700), game.rnd.integerInRange(100, 200), 'balls', game.rnd.integerInRange(0, 6));
4040
s.body.velocity.x = game.rnd.integerInRange(-400, 400);
@@ -48,26 +48,29 @@ function create() {
4848
balls.setAll('body.minBounceVelocity', 0.9);
4949
balls.setAll('body.friction', 0.5);
5050

51+
sprite2 = game.add.sprite(300, 250, 'gameboy', 2);
52+
sprite2.name = 'green';
53+
sprite2.body.collideWorldBounds = true;
54+
// sprite2.body.bounce.setTo(0.5, 0.5);
55+
5156
sprite = game.add.sprite(300, 100, 'gameboy', 0);
5257
sprite.name = 'red';
5358
sprite.body.collideWorldBounds = true;
5459
sprite.body.minBounceVelocity = 0.9;
5560
sprite.body.bounce.setTo(0.5, 0.9);
5661
sprite.body.friction = 0.5;
5762

58-
sprite2 = game.add.sprite(300, 250, 'gameboy', 2);
59-
sprite2.name = 'yellow';
60-
sprite2.body.collideWorldBounds = true;
61-
// sprite2.body.bounce.setTo(0.5, 0.5);
6263

6364
game.input.onDown.add(launch, this);
6465

6566
}
6667

6768
function launch() {
6869

69-
sprite.body.velocity.x = -200;
70-
sprite.body.velocity.y = -200;
70+
game.time._x = true;
71+
72+
// sprite.body.velocity.x = -200;
73+
// sprite.body.velocity.y = -200;
7174

7275
}
7376

@@ -85,28 +88,17 @@ function update() {
8588
game.physics.collide(sprite, layer);
8689
game.physics.collide(sprite2, layer);
8790
game.physics.collide(sprite, sprite2);
88-
89-
if (!flag)
90-
{
91-
for (var i = 0; i < balls._container.children.length; i++)
92-
{
93-
if (balls._container.children[i].y < 5 && balls._container.children[i].body.velocity.y === 0)
94-
{
95-
balls._container.children[i].alpha = 0.5;
96-
console.log(balls._container.children[i]);
97-
flag = true;
98-
}
99-
}
100-
101-
}
102-
91+
10392
}
10493

10594
function render() {
10695

107-
if (sprite)
108-
{
109-
game.debug.renderBodyInfo(sprite, 20, 30);
110-
}
96+
game.debug.renderText(game.time.fps + ' (min: ' + game.time.fpsMin + ' max: ' + game.time.fpsMax + ') ' + game.time.physicsElapsed, 32, 32);
97+
98+
// if (sprite)
99+
// {
100+
// // game.debug.renderBodyInfo(sprite, 20, 30);
101+
// game.debug.renderBodyInfo(sprite2, 20, 230);
102+
// }
111103

112104
}

src/PixiPatch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, rend
7373
displayObject.worldTransform[4],
7474
displayObject.worldTransform[2],
7575
displayObject.worldTransform[5]);
76-
76+
7777
if (displayObject.texture.trimmed)
7878
{
7979
this.context.transform(1, 0, 0, 1, displayObject.texture.trim.x, displayObject.texture.trim.y);

src/physics/arcade/Body.js

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ Phaser.Physics.Arcade.Body = function (sprite) {
135135
this.angle = 0;
136136

137137
/**
138-
* @property {number} minBounceVelocity - The minimum bounce velocity (could just be the bounce value?).
138+
* @property {number} minBounceVelocity - Optional minimum bounce velocity.
139139
*/
140-
this.minBounceVelocity = 0.5;
140+
this.minBounceVelocity = 0.1;
141141

142142
/**
143143
* @property {Phaser.Point} gravity - The gravity applied to the motion of the Body. This works in addition to any gravity set on the world.
@@ -477,6 +477,38 @@ Phaser.Physics.Arcade.Body.prototype = {
477477

478478
},
479479

480+
/**
481+
* Internal method used to check the Body against the World Bounds.
482+
*
483+
* @method Phaser.Physics.Arcade#adjustWorldBounds
484+
* @protected
485+
*/
486+
adjustWorldBounds: function () {
487+
488+
if (this.x < this.game.world.bounds.x)
489+
{
490+
this.x += this.game.world.bounds.x - this.x;
491+
this.preX += this.game.world.bounds.x - this.x;
492+
}
493+
else if (this.right > this.game.world.bounds.right)
494+
{
495+
this.x -= this.right - this.game.world.bounds.right;
496+
this.preX -= this.right - this.game.world.bounds.right;
497+
}
498+
499+
if (this.y < this.game.world.bounds.y)
500+
{
501+
this.y += this.game.world.bounds.y - this.y;
502+
this.preY += this.game.world.bounds.y - this.y;
503+
}
504+
else if (this.bottom > this.game.world.bounds.bottom)
505+
{
506+
this.y -= this.bottom - this.game.world.bounds.bottom;
507+
this.preY -= this.bottom - this.game.world.bounds.bottom;
508+
}
509+
510+
},
511+
480512
/**
481513
* Internal method.
482514
*
@@ -510,16 +542,16 @@ Phaser.Physics.Arcade.Body.prototype = {
510542

511543
this._dx = this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
512544

513-
if (this._dx > this.minBounceVelocity || this.getTotalGravityX() > 0)
514-
{
545+
// if (this._dx > this.minBounceVelocity || this.getTotalGravityX() > 0)
546+
// {
515547
this.x += this._dx;
516548
this.velocity.x += this.motionVelocity.x;
517-
}
518-
else
519-
{
520-
this.preX = this.x;
521-
this.velocity.x = 0;
522-
}
549+
// }
550+
// else
551+
// {
552+
// this.preX = this.x;
553+
// this.velocity.x = 0;
554+
// }
523555
}
524556
else if (this.blocked.right && this.blockedPoint.x > 0)
525557
{
@@ -530,16 +562,16 @@ Phaser.Physics.Arcade.Body.prototype = {
530562

531563
this._dx = this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
532564

533-
if (this._dx < -this.minBounceVelocity || this.getTotalGravityX() < 0)
534-
{
565+
// if (this._dx < -this.minBounceVelocity || this.getTotalGravityX() < 0)
566+
// {
535567
this.x += this._dx;
536568
this.velocity.x += this.motionVelocity.x;
537-
}
538-
else
539-
{
540-
this.preX = this.x;
541-
this.velocity.x = 0;
542-
}
569+
// }
570+
// else
571+
// {
572+
// this.preX = this.x;
573+
// this.velocity.x = 0;
574+
// }
543575
}
544576
else
545577
{
@@ -557,16 +589,16 @@ Phaser.Physics.Arcade.Body.prototype = {
557589

558590
this._dy = this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
559591

560-
if (this._dy > this.minBounceVelocity || this.getTotalGravityY() > 0)
561-
{
592+
// if (this._dy > this.minBounceVelocity || this.getTotalGravityY() > 0)
593+
// {
562594
this.y += this._dy;
563595
this.velocity.y += this.motionVelocity.y;
564-
}
565-
else
566-
{
567-
this.preY = this.y;
568-
this.velocity.y = 0;
569-
}
596+
// }
597+
// else
598+
// {
599+
// this.preY = this.y;
600+
// this.velocity.y = 0;
601+
// }
570602
}
571603
else if (this.blocked.down && this.blockedPoint.y > 0)
572604
{
@@ -577,16 +609,16 @@ Phaser.Physics.Arcade.Body.prototype = {
577609

578610
this._dy = this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
579611

580-
if (this._dy < -this.minBounceVelocity || this.getTotalGravityY() < 0)
581-
{
612+
// if (this._dy < -this.minBounceVelocity || this.getTotalGravityY() < 0)
613+
// {
582614
this.y += this._dy;
583615
this.velocity.y += this.motionVelocity.y;
584-
}
585-
else
586-
{
587-
this.preY = this.y;
588-
this.velocity.y = 0;
589-
}
616+
// }
617+
// else
618+
// {
619+
// this.preY = this.y;
620+
// this.velocity.y = 0;
621+
// }
590622
}
591623
else
592624
{
@@ -1164,7 +1196,7 @@ Phaser.Physics.Arcade.Body.prototype = {
11641196
},
11651197

11661198
/**
1167-
* Internal method. This is called directly before the sprites are sent to the renderer.
1199+
* Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished.
11681200
*
11691201
* @method Phaser.Physics.Arcade#postUpdate
11701202
* @protected
@@ -1173,6 +1205,8 @@ Phaser.Physics.Arcade.Body.prototype = {
11731205

11741206
if (this.moves)
11751207
{
1208+
this.adjustWorldBounds();
1209+
11761210
if (this.deltaX() < 0)
11771211
{
11781212
this.facing = Phaser.LEFT;

src/system/RequestAnimationFrame.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Phaser.RequestAnimationFrame = function(game) {
6060
Phaser.RequestAnimationFrame.prototype = {
6161

6262
/**
63-
* Starts the requestAnimatioFrame running or setTimeout if unavailable in browser
63+
* Starts the requestAnimationFrame running or setTimeout if unavailable in browser
6464
* @method Phaser.RequestAnimationFrame#start
6565
*/
6666
start: function () {

src/time/Time.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ Phaser.Time.prototype = {
237237
this.physicsElapsed = 1.0 * (this.elapsed / 1000);
238238

239239
// Clamp the delta
240-
// if (this.physicsElapsed > 1)
241-
// {
242-
// this.physicsElapsed = 1;
243-
// }
240+
if (this.physicsElapsed > 0.05)
241+
{
242+
this.physicsElapsed = 0.05;
243+
}
244244

245245
// Paused?
246246
if (this.game.paused)

0 commit comments

Comments
 (0)