Preparing for 1.0.6 release, but moving physics changes to dev.

This commit is contained in:
Richard Davey 2013-09-24 15:28:29 +01:00
parent 51049128f5
commit 891369b197
10 changed files with 824 additions and 313 deletions

View file

@ -5,7 +5,7 @@ Phaser 1.0
Phaser is a fast, free and fun open source game framework for making desktop and mobile browser HTML5 games. It uses [Pixi.js](https://github.com/GoodBoyDigital/pixi.js/) internally for fast 2D Canvas and WebGL rendering.
Version: 1.0.5 - Released: September 20th 2013
Version: 1.0.6 - Released: September 24th 2013
By Richard Davey, [Photon Storm](http://www.photonstorm.com)
@ -35,7 +35,16 @@ Phaser is everything we ever wanted from an HTML5 game framework. It will power
Change Log
----------
Version 1.0.6 (in progress)
Version 1.0.7 (in progress in the dev branch)
* Added World.postUpdate - all sprite position changes, as a result of physics, happen here before the render.
* Complete overhaul of Physics.Arcade.Body - now significantly more stable and faster too.
* Updated ArcadePhysics.separateX/Y to use new body system - much better results now.
* QuadTree bug found in 1.0.5 now fixed. The QuadTree is updated properly now using worldTransform values.
* TODO: addMarker hh:mm:ss:ms
* TODO: Direction constants
Version 1.0.6 (September 24th 2013)
* Added check into Pointer.move to always consider a Sprite that has pixelPerfect enabled, regardless of render ID.
* BUG: The pixel perfect click check doesn't work if the sprite is part of a texture atlas yet.
@ -46,14 +55,10 @@ Version 1.0.6 (in progress)
* New: When loading a Sprite Sheet you can now pass negative values for the frame sizes which specifies the number of rows/columns to load instead (thanks TheJare)
* New: BitmapText now supports anchor and has fixed box dimensions (thanks TheJare)
* Fixed bug where if a State contains an empty Preloader the Update will not be called (thanks TheJare)
* Added World.postUpdate - all sprite position changes, as a result of physics, happen here before the render.
* Complete overhaul of Physics.Arcade.Body - now significantly more stable and faster too.
* Updated ArcadePhysics.separateX/Y to use new body system - much better results now.
* QuadTree bug found in 1.0.5 now fixed. The QuadTree is updated properly now using worldTransform values.
* Several new examples added (cameras, tweens, etc)
* TODO: addMarker hh:mm:ss:ms
* TODO: Direction constants
* Added in extra checks to halt collision if it involves an empty Group (thanks cang)
* Added time smoothing to Animation update to help frames hopefully not get too out of sync during long animations with high frame rates.
* Added frame skip to Animation.update. If it gets too far behind it will now skip frames to try and catch up.
Version 1.0.5 (September 20th 2013)
@ -213,6 +218,7 @@ The following list is not exhaustive and is subject to change:
* Joypad support.
* Gestures input class.
* Flash CC html output support.
* Game parameters read from Google Docs.
Right now however our main focus is on documentation and examples, we won't be touching any of the above features until the docs are finished.

File diff suppressed because it is too large Load diff

View file

@ -38,10 +38,11 @@
map.setCollisionRange(18, 47, true, true, true, true);
map.setCollisionRange(53, 69, true, true, true, true);
player = game.add.sprite(32, 32, 'dude');
// player = game.add.sprite(32, 32, 'dude');
player = game.add.sprite(250, 220, 'dude');
player.body.bounce.y = 0.2;
player.body.collideWorldBounds = true;
player.body.gravity.y = 10;
// player.body.gravity.y = 10;
player.animations.add('left', [0, 1, 2, 3], 10, true);
player.animations.add('turn', [4], 20, true);
@ -56,6 +57,7 @@
game.physics.collide(player, map);
player.body.velocity.x = 0;
player.body.velocity.y = 0;
// player.body.acceleration.y = 500;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
@ -96,25 +98,33 @@
facing = 'idle';
}
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP) || game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
if (player.body.touching.down && game.time.now > jumpTimer)
{
player.body.velocity.y = -200;
jumpTimer = game.time.now + 500;
}
player.body.velocity.y = -150;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
player.body.velocity.y = 150;
}
// if (game.input.keyboard.isDown(Phaser.Keyboard.UP) || game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
// {
// if (player.body.touching.down && game.time.now > jumpTimer)
// {
// player.body.velocity.y = -200;
// jumpTimer = game.time.now + 500;
// }
// }
}
function render() {
// game.debug.renderSpriteCorners(p);
// game.debug.renderSpriteCollision(p, 32, 320);
// game.debug.renderText(player.body.velocity.y, 32, 32, 'rgb(255,255,255)');
// game.debug.renderText('left: ' + player.body.touching.left, 32, 32, 'rgb(255,255,255)');
// game.debug.renderText('right: ' + player.body.touching.right, 32, 64, 'rgb(255,255,255)');
game.debug.renderSpriteInfo(player, 32, 32);
game.debug.renderSpriteCorners(player, false, true);
game.debug.renderSpriteCollision(player, 32, 320);
}

View file

@ -79,6 +79,9 @@ Phaser.Animation = function (game, parent, name, frameData, frames, delay, loope
*/
this._frameIndex = 0;
this._frameDiff = 0;
this._frameSkip = 1;
/**
* @property {Phaser.Animation.Frame} currentFrame - The currently displayed frame of the Animation.
*/
@ -181,13 +184,31 @@ Phaser.Animation.prototype = {
if (this.isPlaying == true && this.game.time.now >= this._timeNextFrame)
{
this._frameIndex++;
this._frameSkip = 1;
if (this._frameIndex == this._frames.length)
// Lagging?
this._frameDiff = this.game.time.now - this._timeNextFrame;
this._timeLastFrame = this.game.time.now;
if (this._frameDiff > this.delay)
{
// We need to skip a frame, work out how many
this._frameSkip = Math.floor(this._frameDiff / this.delay);
this._frameDiff -= (this._frameSkip * this.delay);
}
// And what's left now?
this._timeNextFrame = this.game.time.now + (this.delay - this._frameDiff);
this._frameIndex += this._frameSkip;
if (this._frameIndex >= this._frames.length)
{
if (this.looped)
{
this._frameIndex = 0;
this._frameIndex = this._frameIndex - this._frames.length;
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
this._parent.events.onAnimationLoop.dispatch(this._parent, this);
@ -203,9 +224,6 @@ Phaser.Animation.prototype = {
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
}
this._timeLastFrame = this.game.time.now;
this._timeNextFrame = this.game.time.now + this.delay;
return true;
}
@ -260,12 +278,18 @@ Object.defineProperty(Phaser.Animation.prototype, "frameTotal", {
});
/**
* Sets the current frame to the given frame index and updates the texture cache.
* @param {number} value - The frame to display
*
*//**
*
* Returns the current frame, or if not set the index of the most recent frame.
* @returns {Animation.Frame}
*
*/
Object.defineProperty(Phaser.Animation.prototype, "frame", {
/**
* @method frame
* @return {Animation.Frame} Returns the current frame, or if not set the index of the most recent frame.
*/
get: function () {
if (this.currentFrame !== null)
@ -279,10 +303,6 @@ Object.defineProperty(Phaser.Animation.prototype, "frame", {
},
/**
* @method frame
* @return {Number} Sets the current frame to the given frame index and updates the texture cache.
*/
set: function (value) {
this.currentFrame = this._frameData.getFrame(value);

View file

@ -268,6 +268,11 @@ Phaser.Physics.Arcade.prototype = {
collideGroupVsTilemap: function (group, tilemap, collideCallback, processCallback, callbackContext) {
if (group.length == 0)
{
return;
}
if (group._container.first._iNext)
{
var currentNode = group._container.first._iNext;
@ -322,6 +327,11 @@ Phaser.Physics.Arcade.prototype = {
collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext) {
if (group.length == 0)
{
return;
}
// What is the sprite colliding with in the quadtree?
this._potentials = this.quadTree.retrieve(sprite);
@ -353,6 +363,11 @@ Phaser.Physics.Arcade.prototype = {
collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext) {
if (group1.length == 0 || group2.length == 0)
{
return;
}
if (group1._container.first._iNext)
{
var currentNode = group1._container.first._iNext;
@ -629,6 +644,181 @@ Phaser.Physics.Arcade.prototype = {
},
/**
* Separates the two objects on their x axis
* @param object The GameObject to separate
* @param tile The Tile to separate
* @returns {boolean} Whether the objects in fact touched and were separated along the X axis.
*/
OLDseparateTileX: function (object, x, y, width, height, mass, collideLeft, collideRight, separate) {
// Can't separate two immovable objects (tiles are always immovable)
if (object.immovable)
{
return false;
}
// First, get the object delta
this._overlap = 0;
// console.log('separatedX', x, y, object.deltaX());
if (object.deltaX() != 0)
{
this._bounds1.setTo(object.x, object.y, object.width, object.height);
if ((this._bounds1.right > x) && (this._bounds1.x < x + width) && (this._bounds1.bottom > y) && (this._bounds1.y < y + height))
{
// The hulls overlap, let's process it
this._maxOverlap = object.deltaAbsX() + this.OVERLAP_BIAS;
// TODO - We need to check if we're already inside of the tile, i.e. jumping through an n-way tile
// in which case we didn't ought to separate because it'll look like tunneling
if (object.deltaX() > 0)
{
// Going right ...
this._overlap = object.x + object.width - x;
if ((this._overlap > this._maxOverlap) || !object.allowCollision.right || !collideLeft)
{
this._overlap = 0;
}
else
{
object.touching.right = true;
}
}
else if (object.deltaX() < 0)
{
// Going left ...
this._overlap = object.x - width - x;
if ((-this._overlap > this._maxOverlap) || !object.allowCollision.left || !collideRight)
{
this._overlap = 0;
}
else
{
object.touching.left = true;
}
}
}
}
// Then adjust their positions and velocities accordingly (if there was any overlap)
if (this._overlap != 0)
{
if (separate)
{
object.x = object.x - this._overlap;
if (object.bounce.x == 0)
{
object.velocity.x = 0;
}
else
{
object.velocity.x = -object.velocity.x * object.bounce.x;
}
}
return true;
}
else
{
return false;
}
},
/**
* Separates the two objects on their x axis
* @param object The GameObject to separate
* @param tile The Tile to separate
* @returns {boolean} Whether the objects in fact touched and were separated along the X axis.
*/
OLDseparateTileY: function (object, x, y, width, height, mass, collideUp, collideDown, separate) {
// Can't separate two immovable objects (tiles are always immovable)
if (object.immovable)
{
return false;
}
// First, get the object delta
this._overlap = 0;
if (object.deltaY() != 0)
{
this._bounds1.setTo(object.x, object.y, object.width, object.height);
if ((this._bounds1.right > x) && (this._bounds1.x < x + width) && (this._bounds1.bottom > y) && (this._bounds1.y < y + height))
{
// The hulls overlap, let's process it
// Not currently used, may need it so keep for now
this._maxOverlap = object.deltaAbsY() + this.OVERLAP_BIAS;
// TODO - We need to check if we're already inside of the tile, i.e. jumping through an n-way tile
// in which case we didn't ought to separate because it'll look like tunneling
if (object.deltaY() > 0)
{
// Going down ...
this._overlap = object.bottom - y;
// if (object.allowCollision.down && collideDown && this._overlap < this._maxOverlap)
if ((this._overlap > this._maxOverlap) || !object.allowCollision.down || !collideDown)
{
this._overlap = 0;
}
else
{
object.touching.down = true;
}
}
else
{
// Going up ...
this._overlap = object.y - height - y;
if ((-this._overlap > this._maxOverlap) || !object.allowCollision.up || !collideUp)
{
this._overlap = 0;
}
else
{
object.touching.up = true;
}
}
}
}
// Then adjust their positions and velocities accordingly (if there was any overlap)
if (this._overlap != 0)
{
if (separate)
{
object.y = object.y - this._overlap;
if (object.bounce.y == 0)
{
object.velocity.y = 0;
}
else
{
object.velocity.y = -object.velocity.y * object.bounce.y;
}
}
return true;
}
else
{
return false;
}
},
/**
* Separates the two objects on their x axis
* @param object The GameObject to separate
@ -645,17 +835,21 @@ Phaser.Physics.Arcade.prototype = {
this._overlap = 0;
// Do we have any overlap at all?
if (Phaser.Rectangle.intersectsRaw(object, x, x + width, y, y + height))
{
this._maxOverlap = object.deltaAbsX() + this.OVERLAP_BIAS;
if (object.deltaX() == 0)
{
// Object is stuck inside a tile and not moving
// Object is either stuck inside the tile or only overlapping on the Y axis
}
else if (object.deltaX() > 0)
{
// Going right ...
this._overlap = object.x + object.width - x;
if ((this._overlap > this._maxOverlap) || !object.allowCollision.right || !collideLeft)
@ -686,6 +880,7 @@ Phaser.Physics.Arcade.prototype = {
{
if (separate)
{
console.log('x over', this._overlap);
object.x = object.x - this._overlap;
if (object.bounce.x == 0)
@ -762,6 +957,8 @@ Phaser.Physics.Arcade.prototype = {
if (this._overlap != 0)
{
console.log('y over', this._overlap);
if (separate)
{
object.y = object.y - this._overlap;

View file

@ -231,6 +231,7 @@ Phaser.Physics.Arcade.Body.prototype = {
},
// Basically Math.abs
deltaAbsX: function () {
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
},

View file

@ -138,6 +138,8 @@ Phaser.Tilemap.prototype.parseTiledJSON = function (json, key) {
continue;
}
// layer.createQuadTree(json.tilewidth * json.layers[i].width, json.tileheight * json.layers[i].height);
layer.alpha = json.layers[i].opacity;
layer.visible = json.layers[i].visible;
layer.tileMargin = json.tilesets[0].margin;
@ -183,8 +185,6 @@ Phaser.Tilemap.prototype.parseTiledJSON = function (json, key) {
*/
Phaser.Tilemap.prototype.generateTiles = function (qty) {
console.log('generating', qty, 'tiles');
for (var i = 0; i < qty; i++)
{
this.tiles.push(new Phaser.Tile(this.game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));

View file

@ -87,6 +87,8 @@ Phaser.TilemapLayer = function (parent, id, key, mapFormat, name, tileWidth, til
this._alpha = 1;
this.quadTree = null;
this.canvas = null;
this.context = null;
this.baseTexture = null;
@ -472,6 +474,12 @@ Phaser.TilemapLayer.prototype = {
this.parent.addChild(this.sprite);
},
createQuadTree: function (width, height) {
this.quadTree = new Phaser.QuadTree(this, 0, 0, width, height, 20, 4);
},
/**

View file

@ -112,8 +112,15 @@ Phaser.TilemapRenderer.prototype = {
layer.tileWidth,
layer.tileHeight
);
if (tilemap.tiles[this._columnData[tile]].collideNone == false)
{
layer.context.fillStyle = 'rgba(255,255,0,0.5)';
layer.context.fillRect(this._tx, this._ty, layer.tileWidth, layer.tileHeight);
}
}
this._tx += layer.tileWidth;
}

View file

@ -398,8 +398,10 @@ Phaser.Utils.Debug.prototype = {
// this.line('ty: ' + sprite.worldTransform[5]);
// this.line('skew x: ' + sprite.worldTransform[3]);
// this.line('skew y: ' + sprite.worldTransform[1]);
// this.line('dx: ' + sprite.body.deltaX());
// this.line('dy: ' + sprite.body.deltaY());
this.line('dx: ' + sprite.body.deltaX());
this.line('dy: ' + sprite.body.deltaY());
this.line('sdx: ' + sprite.deltaX());
this.line('sdy: ' + sprite.deltaY());
// this.line('inCamera: ' + this.game.renderer.spriteRenderer.inCamera(this.game.camera, sprite));