From dbdb2a20262de57fbde6ee6720b8755d0afe93a1 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Mon, 27 Jan 2014 09:25:12 +0000 Subject: [PATCH] Adjusted delta timer cap and fixed some typos and more examples. --- README.md | 1 + examples/collision/group vs self.js | 1 - examples/display/render texture starfield.js | 2 +- examples/games/matching pairs.js | 6 +- examples/physics/mass velocity test.js | 12 ++- examples/wip/platform.js | 44 ++++---- src/PixiPatch.js | 2 +- src/physics/arcade/Body.js | 104 ++++++++++++------- src/system/RequestAnimationFrame.js | 2 +- src/time/Time.js | 8 +- 10 files changed, 106 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index 12ec053a..c4460265 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,7 @@ Updates: * Removed ArcadePhysics.preUpdate and postUpdate as neither are needed any more. * Body.bottom and Body.right are no longer rounded, so will give accurate sub-pixel values. * Fixed lots of documentation in the Emitter class. +* 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. Bug Fixes: diff --git a/examples/collision/group vs self.js b/examples/collision/group vs self.js index 5d1732dd..33ccc1cb 100644 --- a/examples/collision/group vs self.js +++ b/examples/collision/group vs self.js @@ -28,7 +28,6 @@ function create() { sprites.setAll('body.collideWorldBounds', true); sprites.setAll('body.bounce.x', 1); sprites.setAll('body.bounce.y', 1); - sprites.setAll('body.friction', 0); sprites.setAll('body.minBounceVelocity', 0); } diff --git a/examples/display/render texture starfield.js b/examples/display/render texture starfield.js index 5ee2172b..70df1ffe 100644 --- a/examples/display/render texture starfield.js +++ b/examples/display/render texture starfield.js @@ -1,5 +1,5 @@ -var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update }); function preload() { diff --git a/examples/games/matching pairs.js b/examples/games/matching pairs.js index 701280e3..2d35abd6 100644 --- a/examples/games/matching pairs.js +++ b/examples/games/matching pairs.js @@ -6,7 +6,7 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: function preload() { game.load.tilemap('matching', 'assets/maps/phaser_tiles.json', null, Phaser.Tilemap.TILED_JSON); - game.load.tileset('tiles', 'assets/tiles/phaser_tiles.png', 100, 100, -1, 1, 1); + game.load.image('tiles', 'assets/tiles/phaser_tiles.png'); } @@ -41,9 +41,9 @@ function create() { map = game.add.tilemap('matching'); - tileset = game.add.tileset('tiles'); + // tileset = game.add.tileset('tiles'); - layer = game.add.tilemapLayer(0, 0, 600, 600, tileset, map, 0); + // layer = game.add.tilemapLayer(0, 0, 600, 600, tileset, map, 0); marker = game.add.graphics(); marker.lineStyle(2, 0x00FF00, 1); diff --git a/examples/physics/mass velocity test.js b/examples/physics/mass velocity test.js index 400716d9..69d0405f 100644 --- a/examples/physics/mass velocity test.js +++ b/examples/physics/mass velocity test.js @@ -21,19 +21,25 @@ function create() { s.name = 'alien' + s; s.body.collideWorldBounds = true; s.body.bounce.setTo(0.8, 0.8); + s.body.friction = 0; + s.body.minVelocity.setTo(0, 0); s.body.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40); } car = game.add.sprite(400, 300, 'car'); car.anchor.setTo(0.5, 0.5); car.body.collideWorldBounds = true; - car.body.bounce.setTo(0.8, 0.8); + // car.body.bounce.setTo(0.8, 0.8); car.body.allowRotation = true; + // car.body.immovable = true; + // car.body.minBounceVelocity = 0; } function update() { + game.physics.collide(car, aliens); + car.body.velocity.x = 0; car.body.velocity.y = 0; car.body.angularVelocity = 0; @@ -52,12 +58,10 @@ function update() { car.body.velocity.copyFrom(game.physics.velocityFromAngle(car.angle, 300)); } - game.physics.collide(car, aliens); - } function render() { - game.debug.renderSpriteInfo(car, 32, 32); + game.debug.renderBodyInfo(car, 16, 24); } diff --git a/examples/wip/platform.js b/examples/wip/platform.js index 7bc49c54..fc1a9ecc 100644 --- a/examples/wip/platform.js +++ b/examples/wip/platform.js @@ -34,7 +34,7 @@ function create() { balls = game.add.group(); - for (var i = 0; i < 50; i++) + for (var i = 0; i < 30; i++) { var s = balls.create(game.rnd.integerInRange(100, 700), game.rnd.integerInRange(100, 200), 'balls', game.rnd.integerInRange(0, 6)); s.body.velocity.x = game.rnd.integerInRange(-400, 400); @@ -48,6 +48,11 @@ function create() { balls.setAll('body.minBounceVelocity', 0.9); balls.setAll('body.friction', 0.5); + sprite2 = game.add.sprite(300, 250, 'gameboy', 2); + sprite2.name = 'green'; + sprite2.body.collideWorldBounds = true; + // sprite2.body.bounce.setTo(0.5, 0.5); + sprite = game.add.sprite(300, 100, 'gameboy', 0); sprite.name = 'red'; sprite.body.collideWorldBounds = true; @@ -55,10 +60,6 @@ function create() { sprite.body.bounce.setTo(0.5, 0.9); sprite.body.friction = 0.5; - sprite2 = game.add.sprite(300, 250, 'gameboy', 2); - sprite2.name = 'yellow'; - sprite2.body.collideWorldBounds = true; - // sprite2.body.bounce.setTo(0.5, 0.5); game.input.onDown.add(launch, this); @@ -66,8 +67,10 @@ function create() { function launch() { - sprite.body.velocity.x = -200; - sprite.body.velocity.y = -200; + game.time._x = true; + + // sprite.body.velocity.x = -200; + // sprite.body.velocity.y = -200; } @@ -85,28 +88,17 @@ function update() { game.physics.collide(sprite, layer); game.physics.collide(sprite2, layer); game.physics.collide(sprite, sprite2); - - if (!flag) - { - for (var i = 0; i < balls._container.children.length; i++) - { - if (balls._container.children[i].y < 5 && balls._container.children[i].body.velocity.y === 0) - { - balls._container.children[i].alpha = 0.5; - console.log(balls._container.children[i]); - flag = true; - } - } - - } - + } function render() { - if (sprite) - { - game.debug.renderBodyInfo(sprite, 20, 30); - } + game.debug.renderText(game.time.fps + ' (min: ' + game.time.fpsMin + ' max: ' + game.time.fpsMax + ') ' + game.time.physicsElapsed, 32, 32); + + // if (sprite) + // { + // // game.debug.renderBodyInfo(sprite, 20, 30); + // game.debug.renderBodyInfo(sprite2, 20, 230); + // } } \ No newline at end of file diff --git a/src/PixiPatch.js b/src/PixiPatch.js index 384cae75..e7dd50c9 100644 --- a/src/PixiPatch.js +++ b/src/PixiPatch.js @@ -73,7 +73,7 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, rend displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5]); - + if (displayObject.texture.trimmed) { this.context.transform(1, 0, 0, 1, displayObject.texture.trim.x, displayObject.texture.trim.y); diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index 8d5e366b..58b56c0c 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -135,9 +135,9 @@ Phaser.Physics.Arcade.Body = function (sprite) { this.angle = 0; /** - * @property {number} minBounceVelocity - The minimum bounce velocity (could just be the bounce value?). + * @property {number} minBounceVelocity - Optional minimum bounce velocity. */ - this.minBounceVelocity = 0.5; + this.minBounceVelocity = 0.1; /** * @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 = { }, + /** + * Internal method used to check the Body against the World Bounds. + * + * @method Phaser.Physics.Arcade#adjustWorldBounds + * @protected + */ + adjustWorldBounds: function () { + + if (this.x < this.game.world.bounds.x) + { + this.x += this.game.world.bounds.x - this.x; + this.preX += this.game.world.bounds.x - this.x; + } + else if (this.right > this.game.world.bounds.right) + { + this.x -= this.right - this.game.world.bounds.right; + this.preX -= this.right - this.game.world.bounds.right; + } + + if (this.y < this.game.world.bounds.y) + { + this.y += this.game.world.bounds.y - this.y; + this.preY += this.game.world.bounds.y - this.y; + } + else if (this.bottom > this.game.world.bounds.bottom) + { + this.y -= this.bottom - this.game.world.bounds.bottom; + this.preY -= this.bottom - this.game.world.bounds.bottom; + } + + }, + /** * Internal method. * @@ -510,16 +542,16 @@ Phaser.Physics.Arcade.Body.prototype = { this._dx = this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2); - if (this._dx > this.minBounceVelocity || this.getTotalGravityX() > 0) - { + // if (this._dx > this.minBounceVelocity || this.getTotalGravityX() > 0) + // { this.x += this._dx; this.velocity.x += this.motionVelocity.x; - } - else - { - this.preX = this.x; - this.velocity.x = 0; - } + // } + // else + // { + // this.preX = this.x; + // this.velocity.x = 0; + // } } else if (this.blocked.right && this.blockedPoint.x > 0) { @@ -530,16 +562,16 @@ Phaser.Physics.Arcade.Body.prototype = { this._dx = this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2); - if (this._dx < -this.minBounceVelocity || this.getTotalGravityX() < 0) - { + // if (this._dx < -this.minBounceVelocity || this.getTotalGravityX() < 0) + // { this.x += this._dx; this.velocity.x += this.motionVelocity.x; - } - else - { - this.preX = this.x; - this.velocity.x = 0; - } + // } + // else + // { + // this.preX = this.x; + // this.velocity.x = 0; + // } } else { @@ -557,16 +589,16 @@ Phaser.Physics.Arcade.Body.prototype = { this._dy = this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2); - if (this._dy > this.minBounceVelocity || this.getTotalGravityY() > 0) - { + // if (this._dy > this.minBounceVelocity || this.getTotalGravityY() > 0) + // { this.y += this._dy; this.velocity.y += this.motionVelocity.y; - } - else - { - this.preY = this.y; - this.velocity.y = 0; - } + // } + // else + // { + // this.preY = this.y; + // this.velocity.y = 0; + // } } else if (this.blocked.down && this.blockedPoint.y > 0) { @@ -577,16 +609,16 @@ Phaser.Physics.Arcade.Body.prototype = { this._dy = this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2); - if (this._dy < -this.minBounceVelocity || this.getTotalGravityY() < 0) - { + // if (this._dy < -this.minBounceVelocity || this.getTotalGravityY() < 0) + // { this.y += this._dy; this.velocity.y += this.motionVelocity.y; - } - else - { - this.preY = this.y; - this.velocity.y = 0; - } + // } + // else + // { + // this.preY = this.y; + // this.velocity.y = 0; + // } } else { @@ -1164,7 +1196,7 @@ Phaser.Physics.Arcade.Body.prototype = { }, /** - * Internal method. This is called directly before the sprites are sent to the renderer. + * Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished. * * @method Phaser.Physics.Arcade#postUpdate * @protected @@ -1173,6 +1205,8 @@ Phaser.Physics.Arcade.Body.prototype = { if (this.moves) { + this.adjustWorldBounds(); + if (this.deltaX() < 0) { this.facing = Phaser.LEFT; diff --git a/src/system/RequestAnimationFrame.js b/src/system/RequestAnimationFrame.js index 34c02ba5..fd86aefc 100644 --- a/src/system/RequestAnimationFrame.js +++ b/src/system/RequestAnimationFrame.js @@ -60,7 +60,7 @@ Phaser.RequestAnimationFrame = function(game) { Phaser.RequestAnimationFrame.prototype = { /** - * Starts the requestAnimatioFrame running or setTimeout if unavailable in browser + * Starts the requestAnimationFrame running or setTimeout if unavailable in browser * @method Phaser.RequestAnimationFrame#start */ start: function () { diff --git a/src/time/Time.js b/src/time/Time.js index a1013852..d5702c48 100644 --- a/src/time/Time.js +++ b/src/time/Time.js @@ -237,10 +237,10 @@ Phaser.Time.prototype = { this.physicsElapsed = 1.0 * (this.elapsed / 1000); // Clamp the delta - // if (this.physicsElapsed > 1) - // { - // this.physicsElapsed = 1; - // } + if (this.physicsElapsed > 0.05) + { + this.physicsElapsed = 0.05; + } // Paused? if (this.game.paused)