Adjusted delta timer cap and fixed some typos and more examples.

This commit is contained in:
photonstorm
2014-01-27 09:25:12 +00:00
parent 4432d37e6e
commit dbdb2a2026
10 changed files with 106 additions and 76 deletions
+1
View File
@@ -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:
-1
View File
@@ -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);
}
+1 -1
View File
@@ -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() {
+3 -3
View File
@@ -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);
+8 -4
View File
@@ -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);
}
+18 -26
View File
@@ -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);
// }
}
+1 -1
View File
@@ -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);
+69 -35
View File
@@ -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;
+1 -1
View File
@@ -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 () {
+4 -4
View File
@@ -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)