Skip to content

Commit 67bd653

Browse files
committed
Graphics updated and restored. Working through fixing up Physics.
1 parent c429787 commit 67bd653

4 files changed

Lines changed: 47 additions & 63 deletions

File tree

examples/physics/ship trail.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ function create() {
2222
var bg = game.add.sprite(0, 0, bmd);
2323
bg.body.moves = false;
2424

25+
game.enableStep();
26+
2527
game.physics.gravity.y = 100;
2628

2729
sprite = game.add.sprite(32, 450, 'arrow');
@@ -61,5 +63,6 @@ function update() {
6163
function render() {
6264

6365
game.debug.renderBodyInfo(sprite, 16, 24);
66+
game.debug.renderPhysicsBody(sprite.body);
6467

6568
}

src/gameobjects/Graphics.js

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ Phaser.Graphics.prototype.destroy = function() {
4242

4343
this.clear();
4444

45-
if (this.group)
45+
if (this.parent)
4646
{
47-
this.group.remove(this);
47+
this.parent.remove(this);
4848
}
4949

5050
this.game = null;
@@ -53,6 +53,8 @@ Phaser.Graphics.prototype.destroy = function() {
5353

5454
/*
5555
* Draws a {Phaser.Polygon} or a {PIXI.Polygon} filled
56+
*
57+
* @method Phaser.Sprite.prototype.drawPolygon
5658
*/
5759
Phaser.Graphics.prototype.drawPolygon = function (poly) {
5860

@@ -67,38 +69,11 @@ Phaser.Graphics.prototype.drawPolygon = function (poly) {
6769

6870
}
6971

70-
Object.defineProperty(Phaser.Graphics.prototype, 'angle', {
71-
72-
get: function() {
73-
return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation));
74-
},
75-
76-
set: function(value) {
77-
this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value));
78-
}
79-
80-
});
81-
82-
Object.defineProperty(Phaser.Graphics.prototype, 'x', {
83-
84-
get: function() {
85-
return this.position.x;
86-
},
87-
88-
set: function(value) {
89-
this.position.x = value;
90-
}
91-
92-
});
93-
94-
Object.defineProperty(Phaser.Graphics.prototype, 'y', {
95-
96-
get: function() {
97-
return this.position.y;
98-
},
99-
100-
set: function(value) {
101-
this.position.y = value;
102-
}
103-
104-
});
72+
/**
73+
* 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.
74+
* 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.
75+
* 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.
76+
*
77+
* @name Phaser.Button#angle
78+
* @property {number} angle - The angle of this Button in degrees.
79+
*/

src/gameobjects/Sprite.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
4848
* @property {number} type - The const type of this object.
4949
* @readonly
5050
*/
51-
this.type = Phaser.IMAGE;
51+
this.type = Phaser.SPRITE;
5252

5353
/**
5454
* @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) {
151151
* @property {array} _cache - A small cache for previous step values. 0 = x, 1 = y, 2 = rotation, 3 = renderID, 4 = fresh? (0 = no, 1 = yes)
152152
* @private
153153
*/
154-
this._cache = [0, 0, 0, 0];
154+
this._cache = [0, 0, 0, 0, 1];
155155

156156
};
157157

158158
Phaser.Sprite.prototype = Object.create(PIXI.Sprite.prototype);
159-
Phaser.Sprite.prototype.constructor = Phaser.Image;
159+
Phaser.Sprite.prototype.constructor = Phaser.Sprite;
160160

161161
/**
162162
* Automatically called by World.preUpdate.
163163
*
164-
* @method Phaser.Image#preUpdate
165-
* @memberof Phaser.Image
164+
* @method Phaser.Sprite#preUpdate
165+
* @memberof Phaser.Sprite
166166
*/
167167
Phaser.Sprite.prototype.preUpdate = function() {
168168

169-
if (this._cache[4])
169+
if (this._cache[4] === 1)
170170
{
171+
console.log('sprite cache fresh');
171172
this.world.setTo(this.parent.position.x + this.position.x, this.parent.position.y + this.position.y);
172173
this.worldTransform[2] = this.world.x;
173174
this.worldTransform[5] = this.world.y;
175+
// this._cache[0] = this.world.x;
176+
// this._cache[1] = this.world.y;
177+
// this._cache[2] = this.rotation;
174178
this._cache[4] = 0;
175179

176180
if (this.body)
@@ -262,8 +266,8 @@ Phaser.Sprite.prototype.preUpdate = function() {
262266
/**
263267
* Internal function called by the World postUpdate cycle.
264268
*
265-
* @method Phaser.Image#postUpdate
266-
* @memberof Phaser.Image
269+
* @method Phaser.Sprite#postUpdate
270+
* @memberof Phaser.Sprite
267271
*/
268272
Phaser.Sprite.prototype.postUpdate = function() {
269273

@@ -281,8 +285,8 @@ Phaser.Sprite.prototype.postUpdate = function() {
281285

282286
if (this.fixedToCamera)
283287
{
284-
this.position.x = this.game.camera.view.x + this.x;
285-
this.position.y = this.game.camera.view.y + this.y;
288+
// this.position.x = this.game.camera.view.x + this.x;
289+
// this.position.y = this.game.camera.view.y + this.y;
286290
}
287291
}
288292

@@ -292,8 +296,8 @@ Phaser.Sprite.prototype.postUpdate = function() {
292296
* Changes the Texture the Sprite is using entirely. The old texture is removed and the new one is referenced or fetched from the Cache.
293297
* This causes a WebGL texture update, so use sparingly or in low-intensity portions of your game.
294298
*
295-
* @method Phaser.Image#loadTexture
296-
* @memberof Phaser.Image
299+
* @method Phaser.Sprite#loadTexture
300+
* @memberof Phaser.Sprite
297301
* @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.
298302
* @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.
299303
*/
@@ -358,8 +362,8 @@ Phaser.Sprite.prototype.loadTexture = function (key, frame) {
358362
* Crop allows you to crop the texture used to display this Image.
359363
* Cropping takes place from the top-left of the Image and can be modified in real-time by providing an updated rectangle object.
360364
*
361-
* @method Phaser.Image#crop
362-
* @memberof Phaser.Image
365+
* @method Phaser.Sprite#crop
366+
* @memberof Phaser.Sprite
363367
* @param {Phaser.Rectangle} rect - The Rectangle to crop the Image to. Pass null or no parameters to clear a previously set crop rectangle.
364368
*/
365369
Phaser.Sprite.prototype.crop = function(rect) {
@@ -614,7 +618,7 @@ Phaser.Sprite.prototype.play = function (name, frameRate, loop, killOnComplete)
614618
* 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.
615619
* 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.
616620
*
617-
* @name Phaser.Image#angle
621+
* @name Phaser.Sprite#angle
618622
* @property {number} angle - The angle of this Image in degrees.
619623
*/
620624
Object.defineProperty(Phaser.Sprite.prototype, "angle", {
@@ -636,7 +640,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "angle", {
636640
/**
637641
* Returns the delta x value. The difference between world.x now and in the previous step.
638642
*
639-
* @name Phaser.Image#deltaX
643+
* @name Phaser.Sprite#deltaX
640644
* @property {number} deltaX - The delta value. Positive if the motion was to the right, negative if to the left.
641645
* @readonly
642646
*/
@@ -653,7 +657,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "deltaX", {
653657
/**
654658
* Returns the delta y value. The difference between world.y now and in the previous step.
655659
*
656-
* @name Phaser.Image#deltaY
660+
* @name Phaser.Sprite#deltaY
657661
* @property {number} deltaY - The delta value. Positive if the motion was downwards, negative if upwards.
658662
* @readonly
659663
*/
@@ -670,7 +674,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "deltaY", {
670674
/**
671675
* Returns the delta z value. The difference between rotation now and in the previous step.
672676
*
673-
* @name Phaser.Image#deltaZ
677+
* @name Phaser.Sprite#deltaZ
674678
* @property {number} deltaZ - The delta value.
675679
* @readonly
676680
*/
@@ -687,7 +691,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "deltaZ", {
687691
/**
688692
* Checks if the Image bounds are within the game world, otherwise false if fully outside of it.
689693
*
690-
* @name Phaser.Image#inWorld
694+
* @name Phaser.Sprite#inWorld
691695
* @property {boolean} inWorld - True if the Image bounds is within the game world, even if only partially. Otherwise false if fully outside of it.
692696
* @readonly
693697
*/
@@ -704,7 +708,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "inWorld", {
704708
/**
705709
* Checks if the Image bounds are within the game camera, otherwise false if fully outside of it.
706710
*
707-
* @name Phaser.Image#inCamera
711+
* @name Phaser.Sprite#inCamera
708712
* @property {boolean} inCamera - True if the Image bounds is within the game camera, even if only partially. Otherwise false if fully outside of it.
709713
* @readonly
710714
*/
@@ -751,7 +755,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "frameName", {
751755
});
752756

753757
/**
754-
* @name Phaser.Image#renderOrderID
758+
* @name Phaser.Sprite#renderOrderID
755759
* @property {number} renderOrderID - The render order ID, reset every frame.
756760
* @readonly
757761
*/
@@ -769,7 +773,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "renderOrderID", {
769773
* By default an Image won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
770774
* activated for this object and it will then start to process click/touch events and more.
771775
*
772-
* @name Phaser.Image#inputEnabled
776+
* @name Phaser.Sprite#inputEnabled
773777
* @property {boolean} inputEnabled - Set to true to allow this object to receive input events.
774778
*/
775779
Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", {

src/physics/arcade/Body.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ Phaser.Physics.Arcade.Body.prototype = {
381381
this.x = (this.sprite.world.x - (this.sprite.anchor.x * this.sprite.width)) + this.offset.x;
382382
this.y = (this.sprite.world.y - (this.sprite.anchor.y * this.sprite.height)) + this.offset.y;
383383

384+
console.log('body pre', this.preX, this.preY, 'now', this.x, this.y);
385+
384386
// This covers any motion that happens during this frame, not since the last frame
385387
this.preX = this.x;
386388
this.preY = this.y;
@@ -889,7 +891,7 @@ Phaser.Physics.Arcade.Body.prototype = {
889891

890892
if (this.inContact(body))
891893
{
892-
return false;
894+
// return false;
893895
}
894896

895897
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 = {
949951
else
950952
{
951953
// They can only contact like this if at least one of their sides is open, otherwise it's a separation
952-
// 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)
953-
// {
954+
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)
955+
{
954956
this.addContact(body);
955-
// }
957+
}
956958
}
957959

958960
return hasSeparated;

0 commit comments

Comments
 (0)