mirror of
https://github.com/wassname/phaser.git
synced 2026-07-17 11:31:30 +08:00
Final 1.0.5 release.
This commit is contained in:
+25
-50
@@ -273,54 +273,6 @@ Phaser.Group.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Call this function to sort the group according to a particular value and order.
|
||||
* For example, to sort game objects for Zelda-style overlaps you might call
|
||||
* <code>myGroup.sort("y",Group.ASCENDING)</code> at the bottom of your
|
||||
* <code>State.update()</code> override. To sort all existing objects after
|
||||
* a big explosion or bomb attack, you might call <code>myGroup.sort("exists",Group.DESCENDING)</code>.
|
||||
*
|
||||
* @param {string} index The <code>string</code> name of the member variable you want to sort on. Default value is "z".
|
||||
* @param {number} order A <code>Group</code> constant that defines the sort order. Possible values are <code>Group.ASCENDING</code> and <code>Group.DESCENDING</code>. Default value is <code>Group.ASCENDING</code>.
|
||||
*/
|
||||
|
||||
// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.c
|
||||
|
||||
sort: function (index, order) {
|
||||
// if (typeof index === "undefined") { index = 'z'; }
|
||||
// if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
|
||||
// var _this = this;
|
||||
// this._sortIndex = index;
|
||||
// this._sortOrder = order;
|
||||
// this.members.sort(function (a, b) {
|
||||
// return _this.sortHandler(a, b);
|
||||
// });
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function for the sort process.
|
||||
*
|
||||
* @param {Basic} Obj1 The first object being sorted.
|
||||
* @param {Basic} Obj2 The second object being sorted.
|
||||
*
|
||||
* @return {number} An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
|
||||
*/
|
||||
sortHandler: function (obj1, obj2) {
|
||||
|
||||
/*
|
||||
if (!obj1 || !obj2) {
|
||||
//console.log('null objects in sort', obj1, obj2);
|
||||
return 0;
|
||||
}
|
||||
if (obj1[this._sortIndex] < obj2[this._sortIndex]) {
|
||||
return this._sortOrder;
|
||||
} else if (obj1[this._sortIndex] > obj2[this._sortIndex]) {
|
||||
return -this._sortOrder;
|
||||
}
|
||||
return 0;
|
||||
*/
|
||||
},
|
||||
|
||||
// key is an ARRAY of values.
|
||||
setProperty: function (child, key, value, operation) {
|
||||
|
||||
@@ -424,8 +376,31 @@ Phaser.Group.prototype = {
|
||||
|
||||
},
|
||||
|
||||
callAllExists: function (callback, callbackContext, existsValue) {
|
||||
|
||||
var args = Array.prototype.splice.call(arguments, 3);
|
||||
|
||||
if (this._container.children.length > 0 && this._container.first._iNext)
|
||||
{
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
if (currentNode.exists == existsValue && currentNode[callback])
|
||||
{
|
||||
currentNode[callback].apply(currentNode, args);
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this._container.last._iNext)
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Calls a function on all of the active children (children with exists=true).
|
||||
* Calls a function on all of the children regardless if they are dead or alive (see callAllExists if you need control over that)
|
||||
* You must pass the context in which the callback is applied.
|
||||
* After the context you can add as many parameters as you like, which will all be passed to the child.
|
||||
*/
|
||||
@@ -439,7 +414,7 @@ Phaser.Group.prototype = {
|
||||
|
||||
do
|
||||
{
|
||||
if (currentNode.exists && currentNode[callback])
|
||||
if (currentNode[callback])
|
||||
{
|
||||
currentNode[callback].apply(currentNode, args);
|
||||
}
|
||||
|
||||
+77
-65
@@ -214,6 +214,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
|
||||
this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y);
|
||||
|
||||
// If this sprite or the camera have moved then let's update everything
|
||||
// Note: The actual position shouldn't be changed if this item is inside a Group?
|
||||
if (this.position.x != this._cache.x || this.position.y != this._cache.y)
|
||||
{
|
||||
this.position.x = this._cache.x;
|
||||
@@ -224,76 +225,77 @@ Phaser.Sprite.prototype.preUpdate = function() {
|
||||
if (this.visible)
|
||||
{
|
||||
this.renderOrderID = this.game.world.currentRenderOrderID++;
|
||||
|
||||
// |a c tx|
|
||||
// |b d ty|
|
||||
// |0 0 1|
|
||||
|
||||
// Only update the values we need
|
||||
if (this.worldTransform[0] != this._cache.a00 || this.worldTransform[1] != this._cache.a01)
|
||||
{
|
||||
this._cache.a00 = this.worldTransform[0]; // scaleX a
|
||||
this._cache.a01 = this.worldTransform[1]; // skewY c
|
||||
this._cache.i01 = this.worldTransform[1]; // skewY c
|
||||
this._cache.scaleX = Math.sqrt((this._cache.a00 * this._cache.a00) + (this._cache.a01 * this._cache.a01)); // round this off a bit?
|
||||
this._cache.a01 *= -1;
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
// Need to test, but probably highly unlikely that a scaleX would happen without effecting the Y skew
|
||||
if (this.worldTransform[3] != this._cache.a10 || this.worldTransform[4] != this._cache.a11)
|
||||
{
|
||||
this._cache.a10 = this.worldTransform[3]; // skewX b
|
||||
this._cache.i10 = this.worldTransform[3]; // skewX b
|
||||
this._cache.a11 = this.worldTransform[4]; // scaleY d
|
||||
this._cache.scaleY = Math.sqrt((this._cache.a10 * this._cache.a10) + (this._cache.a11 * this._cache.a11)); // round this off a bit?
|
||||
this._cache.a10 *= -1;
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
if (this.worldTransform[2] != this._cache.a02 || this.worldTransform[5] != this._cache.a12)
|
||||
{
|
||||
this._cache.a02 = this.worldTransform[2]; // translateX tx
|
||||
this._cache.a12 = this.worldTransform[5]; // translateY ty
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
// Frame updated?
|
||||
if (this.currentFrame.uuid != this._cache.frameID)
|
||||
{
|
||||
this._cache.frameWidth = this.texture.frame.width;
|
||||
this._cache.frameHeight = this.texture.frame.height;
|
||||
this._cache.frameID = this.currentFrame.uuid;
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
if (this._cache.dirty)
|
||||
{
|
||||
this._cache.width = Math.floor(this.currentFrame.sourceSizeW * this._cache.scaleX);
|
||||
this._cache.height = Math.floor(this.currentFrame.sourceSizeH * this._cache.scaleY);
|
||||
this._cache.halfWidth = Math.floor(this._cache.width / 2);
|
||||
this._cache.halfHeight = Math.floor(this._cache.height / 2);
|
||||
|
||||
this._cache.id = 1 / (this._cache.a00 * this._cache.a11 + this._cache.a01 * -this._cache.a10);
|
||||
this._cache.idi = 1 / (this._cache.a00 * this._cache.a11 + this._cache.i01 * -this._cache.i10);
|
||||
|
||||
this.updateBounds();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
// |a c tx|
|
||||
// |b d ty|
|
||||
// |0 0 1|
|
||||
|
||||
// Only update the values we need
|
||||
if (this.worldTransform[0] != this._cache.a00 || this.worldTransform[1] != this._cache.a01)
|
||||
{
|
||||
this._cache.a00 = this.worldTransform[0]; // scaleX a
|
||||
this._cache.a01 = this.worldTransform[1]; // skewY c
|
||||
this._cache.i01 = this.worldTransform[1]; // skewY c
|
||||
this._cache.scaleX = Math.sqrt((this._cache.a00 * this._cache.a00) + (this._cache.a01 * this._cache.a01)); // round this off a bit?
|
||||
this._cache.a01 *= -1;
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
// Need to test, but probably highly unlikely that a scaleX would happen without effecting the Y skew
|
||||
if (this.worldTransform[3] != this._cache.a10 || this.worldTransform[4] != this._cache.a11)
|
||||
{
|
||||
this._cache.a10 = this.worldTransform[3]; // skewX b
|
||||
this._cache.i10 = this.worldTransform[3]; // skewX b
|
||||
this._cache.a11 = this.worldTransform[4]; // scaleY d
|
||||
this._cache.scaleY = Math.sqrt((this._cache.a10 * this._cache.a10) + (this._cache.a11 * this._cache.a11)); // round this off a bit?
|
||||
this._cache.a10 *= -1;
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
if (this.worldTransform[2] != this._cache.a02 || this.worldTransform[5] != this._cache.a12)
|
||||
{
|
||||
this._cache.a02 = this.worldTransform[2]; // translateX tx
|
||||
this._cache.a12 = this.worldTransform[5]; // translateY ty
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
// Frame updated?
|
||||
if (this.currentFrame.uuid != this._cache.frameID)
|
||||
{
|
||||
this._cache.frameWidth = this.texture.frame.width;
|
||||
this._cache.frameHeight = this.texture.frame.height;
|
||||
this._cache.frameID = this.currentFrame.uuid;
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
if (this._cache.dirty)
|
||||
{
|
||||
this._cache.width = Math.floor(this.currentFrame.sourceSizeW * this._cache.scaleX);
|
||||
this._cache.height = Math.floor(this.currentFrame.sourceSizeH * this._cache.scaleY);
|
||||
this._cache.halfWidth = Math.floor(this._cache.width / 2);
|
||||
this._cache.halfHeight = Math.floor(this._cache.height / 2);
|
||||
|
||||
this._cache.id = 1 / (this._cache.a00 * this._cache.a11 + this._cache.a01 * -this._cache.a10);
|
||||
this._cache.idi = 1 / (this._cache.a00 * this._cache.a11 + this._cache.i01 * -this._cache.i10);
|
||||
|
||||
this.updateBounds();
|
||||
}
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// We still need to work out the bounds in case the camera has moved
|
||||
// but we can't use the local or worldTransform to do it, as Pixi resets that if a Sprite is invisible.
|
||||
// So we'll compare against the cached state + new position.
|
||||
if (this._cache.dirty && this.visible == false)
|
||||
{
|
||||
this.bounds.x -= this._cache.boundsX - this._cache.x;
|
||||
this._cache.boundsX = this._cache.x;
|
||||
// if (this._cache.dirty && this.visible == false)
|
||||
// {
|
||||
// this.bounds.x -= this._cache.boundsX - this._cache.x;
|
||||
// this._cache.boundsX = this._cache.x;
|
||||
|
||||
this.bounds.y -= this._cache.boundsY - this._cache.y;
|
||||
this._cache.boundsY = this._cache.y;
|
||||
}
|
||||
}
|
||||
// this.bounds.y -= this._cache.boundsY - this._cache.y;
|
||||
// this._cache.boundsY = this._cache.y;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Re-run the camera visibility check
|
||||
if (this._cache.dirty)
|
||||
@@ -302,7 +304,8 @@ Phaser.Sprite.prototype.preUpdate = function() {
|
||||
|
||||
if (this.autoCull == true)
|
||||
{
|
||||
this.visible = this._cache.cameraVisible;
|
||||
// Won't get rendered but will still get its transform updated
|
||||
this.renderable = this._cache.cameraVisible;
|
||||
}
|
||||
|
||||
// Update our physics bounds
|
||||
@@ -313,6 +316,15 @@ Phaser.Sprite.prototype.preUpdate = function() {
|
||||
|
||||
}
|
||||
|
||||
Phaser.Sprite.prototype.postUpdate = function() {
|
||||
|
||||
if (this.exists)
|
||||
{
|
||||
this.body.postUpdate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the sprite so its center is located on the given x and y coordinates.
|
||||
* Doesn't change the origin of the sprite.
|
||||
|
||||
@@ -17,6 +17,9 @@ Phaser.Text = function (game, x, y, text, style) {
|
||||
|
||||
this.game = game;
|
||||
|
||||
this._text = text;
|
||||
this._style = style;
|
||||
|
||||
PIXI.Text.call(this, text, style);
|
||||
|
||||
this.type = Phaser.TEXT;
|
||||
@@ -91,3 +94,40 @@ Object.defineProperty(Phaser.Text.prototype, 'angle', {
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Text.prototype, 'text', {
|
||||
|
||||
get: function() {
|
||||
return this._text;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
// Let's not update unless needed, this way we can safely update the text in a core loop without constant re-draws
|
||||
if (value !== this._text)
|
||||
{
|
||||
this._text = value;
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Text.prototype, 'style', {
|
||||
|
||||
get: function() {
|
||||
return this._style;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
// Let's not update unless needed, this way we can safely update the text in a core loop without constant re-draws
|
||||
if (value !== this._style)
|
||||
{
|
||||
this._style = value;
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -7,6 +7,8 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
|
||||
this.x = sprite.x;
|
||||
this.y = sprite.y;
|
||||
this.lastX = sprite.x;
|
||||
this.lastY = sprite.y;
|
||||
|
||||
// un-scaled original size
|
||||
this.sourceWidth = sprite.currentFrame.sourceSizeW;
|
||||
@@ -62,9 +64,6 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
|
||||
this.collideWorldBounds = false;
|
||||
|
||||
this.lastX = sprite.x;
|
||||
this.lastY = sprite.y;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Physics.Arcade.Body.prototype = {
|
||||
@@ -102,8 +101,11 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.lastY = this.y;
|
||||
this.rotation = this.sprite.angle;
|
||||
|
||||
// There is a bug here in that the worldTransform values are what should be used, otherwise the quadTree gets the wrong rect given to it
|
||||
this.x = (this.sprite.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.y = (this.sprite.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
// this.x = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
// this.y = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
|
||||
if (this.moves)
|
||||
{
|
||||
@@ -122,6 +124,16 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.game.physics.quadTree.insert(this);
|
||||
}
|
||||
|
||||
if (this.deltaX() != 0)
|
||||
{
|
||||
this.sprite.x -= this.deltaX();
|
||||
}
|
||||
|
||||
if (this.deltaY() != 0)
|
||||
{
|
||||
this.sprite.y -= this.deltaY();
|
||||
}
|
||||
|
||||
// Adjust the sprite based on all of the above, so the x/y coords will be correct going into the State update
|
||||
this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width);
|
||||
this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height);
|
||||
|
||||
+45
-5
@@ -119,6 +119,14 @@ Phaser.Utils.Debug.prototype = {
|
||||
this.context.strokeStyle = color;
|
||||
this.context.strokeRect(bounds.x, bounds.y, bounds.width, bounds.height);
|
||||
this.renderText(quadtree.ID + ' / ' + quadtree.objects.length, bounds.x + 4, bounds.y + 16, 'rgb(0,200,0)', '12px Courier');
|
||||
|
||||
this.context.strokeStyle = 'rgb(0,255,0)';
|
||||
|
||||
// children
|
||||
for (var i = 0; i < quadtree.objects.length; i++)
|
||||
{
|
||||
this.context.strokeRect(quadtree.objects[i].x, quadtree.objects[i].y, quadtree.objects[i].width, quadtree.objects[i].height);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -374,6 +382,7 @@ Phaser.Utils.Debug.prototype = {
|
||||
this.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
|
||||
this.line('visible: ' + sprite.visible);
|
||||
this.line('in camera: ' + sprite.inCamera);
|
||||
this.line('body x: ' + sprite.body.x.toFixed(1) + ' y: ' + sprite.body.y.toFixed(1));
|
||||
|
||||
// 0 = scaleX
|
||||
// 1 = skewY
|
||||
@@ -382,7 +391,6 @@ Phaser.Utils.Debug.prototype = {
|
||||
// 4 = scaleY
|
||||
// 5 = translateY
|
||||
|
||||
|
||||
// this.line('id: ' + sprite._id);
|
||||
// this.line('scale x: ' + sprite.worldTransform[0]);
|
||||
// this.line('scale y: ' + sprite.worldTransform[4]);
|
||||
@@ -390,6 +398,8 @@ 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('inCamera: ' + this.game.renderer.spriteRenderer.inCamera(this.game.camera, sprite));
|
||||
|
||||
@@ -454,18 +464,48 @@ Phaser.Utils.Debug.prototype = {
|
||||
|
||||
},
|
||||
|
||||
renderSpriteBounds: function (sprite, color) {
|
||||
renderSpriteBody: function (sprite, color) {
|
||||
|
||||
if (this.context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
color = color || 'rgba(0, 255, 0, 0.2)';
|
||||
color = color || 'rgba(255,0,255, 0.3)';
|
||||
|
||||
this.start(0, 0, color);
|
||||
|
||||
this.start();
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(sprite.worldView.x, sprite.worldView.y, sprite.worldView.width, sprite.worldView.height);
|
||||
// this.context.fillRect(sprite.body.x - sprite.body.deltaX(), sprite.body.y - sprite.body.deltaY(), sprite.body.width, sprite.body.height);
|
||||
this.context.fillRect(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height);
|
||||
|
||||
this.stop();
|
||||
|
||||
},
|
||||
|
||||
renderSpriteBounds: function (sprite, color, fill) {
|
||||
|
||||
if (this.context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
color = color || 'rgb(255,0,255)';
|
||||
|
||||
this.start(0, 0, color);
|
||||
|
||||
if (fill)
|
||||
{
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(sprite.bounds.x, sprite.bounds.y, sprite.bounds.width, sprite.bounds.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.context.strokeStyle = color;
|
||||
this.context.strokeRect(sprite.bounds.x, sprite.bounds.y, sprite.bounds.width, sprite.bounds.height);
|
||||
this.context.stroke();
|
||||
}
|
||||
|
||||
this.stop();
|
||||
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user