mirror of
https://github.com/wassname/phaser.git
synced 2026-08-03 13:10:25 +08:00
Preparing for 1.0.6 release, but moving physics changes to dev.
This commit is contained in:
+34
-14
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -231,6 +231,7 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
},
|
||||
|
||||
// Basically Math.abs
|
||||
deltaAbsX: function () {
|
||||
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
|
||||
},
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
+4
-2
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user