Graphics updated and restored. Working through fixing up Physics.

This commit is contained in:
photonstorm
2014-02-07 19:44:14 +00:00
parent c429787877
commit 67bd653eb4
4 changed files with 47 additions and 63 deletions
+3
View File
@@ -22,6 +22,8 @@ function create() {
var bg = game.add.sprite(0, 0, bmd);
bg.body.moves = false;
game.enableStep();
game.physics.gravity.y = 100;
sprite = game.add.sprite(32, 450, 'arrow');
@@ -61,5 +63,6 @@ function update() {
function render() {
game.debug.renderBodyInfo(sprite, 16, 24);
game.debug.renderPhysicsBody(sprite.body);
}
+12 -37
View File
@@ -42,9 +42,9 @@ Phaser.Graphics.prototype.destroy = function() {
this.clear();
if (this.group)
if (this.parent)
{
this.group.remove(this);
this.parent.remove(this);
}
this.game = null;
@@ -53,6 +53,8 @@ Phaser.Graphics.prototype.destroy = function() {
/*
* Draws a {Phaser.Polygon} or a {PIXI.Polygon} filled
*
* @method Phaser.Sprite.prototype.drawPolygon
*/
Phaser.Graphics.prototype.drawPolygon = function (poly) {
@@ -67,38 +69,11 @@ Phaser.Graphics.prototype.drawPolygon = function (poly) {
}
Object.defineProperty(Phaser.Graphics.prototype, 'angle', {
get: function() {
return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation));
},
set: function(value) {
this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value));
}
});
Object.defineProperty(Phaser.Graphics.prototype, 'x', {
get: function() {
return this.position.x;
},
set: function(value) {
this.position.x = value;
}
});
Object.defineProperty(Phaser.Graphics.prototype, 'y', {
get: function() {
return this.position.y;
},
set: function(value) {
this.position.y = value;
}
});
/**
* Indicates the rotation of the Button in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
* Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.
* If you wish to work in radians instead of degrees use the rotation property instead. Working in radians is also a little faster as it doesn't have to convert the angle.
*
* @name Phaser.Button#angle
* @property {number} angle - The angle of this Button in degrees.
*/
+26 -22
View File
@@ -48,7 +48,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
* @property {number} type - The const type of this object.
* @readonly
*/
this.type = Phaser.IMAGE;
this.type = Phaser.SPRITE;
/**
* @property {Phaser.Events} events - The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.
@@ -151,26 +151,30 @@ Phaser.Sprite = function (game, x, y, key, frame) {
* @property {array} _cache - A small cache for previous step values. 0 = x, 1 = y, 2 = rotation, 3 = renderID, 4 = fresh? (0 = no, 1 = yes)
* @private
*/
this._cache = [0, 0, 0, 0];
this._cache = [0, 0, 0, 0, 1];
};
Phaser.Sprite.prototype = Object.create(PIXI.Sprite.prototype);
Phaser.Sprite.prototype.constructor = Phaser.Image;
Phaser.Sprite.prototype.constructor = Phaser.Sprite;
/**
* Automatically called by World.preUpdate.
*
* @method Phaser.Image#preUpdate
* @memberof Phaser.Image
* @method Phaser.Sprite#preUpdate
* @memberof Phaser.Sprite
*/
Phaser.Sprite.prototype.preUpdate = function() {
if (this._cache[4])
if (this._cache[4] === 1)
{
console.log('sprite cache fresh');
this.world.setTo(this.parent.position.x + this.position.x, this.parent.position.y + this.position.y);
this.worldTransform[2] = this.world.x;
this.worldTransform[5] = this.world.y;
// this._cache[0] = this.world.x;
// this._cache[1] = this.world.y;
// this._cache[2] = this.rotation;
this._cache[4] = 0;
if (this.body)
@@ -262,8 +266,8 @@ Phaser.Sprite.prototype.preUpdate = function() {
/**
* Internal function called by the World postUpdate cycle.
*
* @method Phaser.Image#postUpdate
* @memberof Phaser.Image
* @method Phaser.Sprite#postUpdate
* @memberof Phaser.Sprite
*/
Phaser.Sprite.prototype.postUpdate = function() {
@@ -281,8 +285,8 @@ Phaser.Sprite.prototype.postUpdate = function() {
if (this.fixedToCamera)
{
this.position.x = this.game.camera.view.x + this.x;
this.position.y = this.game.camera.view.y + this.y;
// this.position.x = this.game.camera.view.x + this.x;
// this.position.y = this.game.camera.view.y + this.y;
}
}
@@ -292,8 +296,8 @@ Phaser.Sprite.prototype.postUpdate = function() {
* Changes the Texture the Sprite is using entirely. The old texture is removed and the new one is referenced or fetched from the Cache.
* This causes a WebGL texture update, so use sparingly or in low-intensity portions of your game.
*
* @method Phaser.Image#loadTexture
* @memberof Phaser.Image
* @method Phaser.Sprite#loadTexture
* @memberof Phaser.Sprite
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
* @param {string|number} frame - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
*/
@@ -358,8 +362,8 @@ Phaser.Sprite.prototype.loadTexture = function (key, frame) {
* Crop allows you to crop the texture used to display this Image.
* Cropping takes place from the top-left of the Image and can be modified in real-time by providing an updated rectangle object.
*
* @method Phaser.Image#crop
* @memberof Phaser.Image
* @method Phaser.Sprite#crop
* @memberof Phaser.Sprite
* @param {Phaser.Rectangle} rect - The Rectangle to crop the Image to. Pass null or no parameters to clear a previously set crop rectangle.
*/
Phaser.Sprite.prototype.crop = function(rect) {
@@ -614,7 +618,7 @@ Phaser.Sprite.prototype.play = function (name, frameRate, loop, killOnComplete)
* Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.
* If you wish to work in radians instead of degrees use the property Sprite.rotation instead. Working in radians is also a little faster as it doesn't have to convert the angle.
*
* @name Phaser.Image#angle
* @name Phaser.Sprite#angle
* @property {number} angle - The angle of this Image in degrees.
*/
Object.defineProperty(Phaser.Sprite.prototype, "angle", {
@@ -636,7 +640,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "angle", {
/**
* Returns the delta x value. The difference between world.x now and in the previous step.
*
* @name Phaser.Image#deltaX
* @name Phaser.Sprite#deltaX
* @property {number} deltaX - The delta value. Positive if the motion was to the right, negative if to the left.
* @readonly
*/
@@ -653,7 +657,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "deltaX", {
/**
* Returns the delta y value. The difference between world.y now and in the previous step.
*
* @name Phaser.Image#deltaY
* @name Phaser.Sprite#deltaY
* @property {number} deltaY - The delta value. Positive if the motion was downwards, negative if upwards.
* @readonly
*/
@@ -670,7 +674,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "deltaY", {
/**
* Returns the delta z value. The difference between rotation now and in the previous step.
*
* @name Phaser.Image#deltaZ
* @name Phaser.Sprite#deltaZ
* @property {number} deltaZ - The delta value.
* @readonly
*/
@@ -687,7 +691,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "deltaZ", {
/**
* Checks if the Image bounds are within the game world, otherwise false if fully outside of it.
*
* @name Phaser.Image#inWorld
* @name Phaser.Sprite#inWorld
* @property {boolean} inWorld - True if the Image bounds is within the game world, even if only partially. Otherwise false if fully outside of it.
* @readonly
*/
@@ -704,7 +708,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "inWorld", {
/**
* Checks if the Image bounds are within the game camera, otherwise false if fully outside of it.
*
* @name Phaser.Image#inCamera
* @name Phaser.Sprite#inCamera
* @property {boolean} inCamera - True if the Image bounds is within the game camera, even if only partially. Otherwise false if fully outside of it.
* @readonly
*/
@@ -751,7 +755,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "frameName", {
});
/**
* @name Phaser.Image#renderOrderID
* @name Phaser.Sprite#renderOrderID
* @property {number} renderOrderID - The render order ID, reset every frame.
* @readonly
*/
@@ -769,7 +773,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "renderOrderID", {
* By default an Image won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
* activated for this object and it will then start to process click/touch events and more.
*
* @name Phaser.Image#inputEnabled
* @name Phaser.Sprite#inputEnabled
* @property {boolean} inputEnabled - Set to true to allow this object to receive input events.
*/
Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", {
+6 -4
View File
@@ -381,6 +381,8 @@ Phaser.Physics.Arcade.Body.prototype = {
this.x = (this.sprite.world.x - (this.sprite.anchor.x * this.sprite.width)) + this.offset.x;
this.y = (this.sprite.world.y - (this.sprite.anchor.y * this.sprite.height)) + this.offset.y;
console.log('body pre', this.preX, this.preY, 'now', this.x, this.y);
// This covers any motion that happens during this frame, not since the last frame
this.preX = this.x;
this.preY = this.y;
@@ -889,7 +891,7 @@ Phaser.Physics.Arcade.Body.prototype = {
if (this.inContact(body))
{
return false;
// return false;
}
this._distances[0] = body.right - this.x; // Distance of B to face on left side of A
@@ -949,10 +951,10 @@ Phaser.Physics.Arcade.Body.prototype = {
else
{
// They can only contact like this if at least one of their sides is open, otherwise it's a separation
// if (!this.checkCollision.up || !this.checkCollision.down || !this.checkCollision.left || !this.checkCollision.right || !body.checkCollision.up || !body.checkCollision.down || !body.checkCollision.left || !body.checkCollision.right)
// {
if (!this.checkCollision.up || !this.checkCollision.down || !this.checkCollision.left || !this.checkCollision.right || !body.checkCollision.up || !body.checkCollision.down || !body.checkCollision.left || !body.checkCollision.right)
{
this.addContact(body);
// }
}
}
return hasSeparated;