mirror of
https://github.com/wassname/phaser.git
synced 2026-07-12 00:50:45 +08:00
Updated world so the update run uses the linked list. Sprite.getLocalPosition now almost working, but falls over for children.
This commit is contained in:
+22
-4
@@ -14,37 +14,55 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
var s;
|
||||
var s2;
|
||||
|
||||
function preload() {
|
||||
game.load.image('mushroom', 'assets/sprites/mana_card.png');
|
||||
game.load.image('card', 'assets/sprites/mana_card.png');
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
s = game.add.sprite(game.world.centerX, game.world.centerY, 'mushroom');
|
||||
s = game.add.sprite(game.world.centerX, game.world.centerY, 'card');
|
||||
s2 = game.add.sprite(100, 100, 'mushroom');
|
||||
s2.name = 'm';
|
||||
|
||||
s.addChild(s2);
|
||||
|
||||
s.anchor.setTo(0.5, 0.5);
|
||||
s2.anchor.setTo(0.5, 0.5);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
s.angle += 0.5;
|
||||
// s2.angle += 1;
|
||||
|
||||
if (s.scale.x > -2)
|
||||
{
|
||||
s.scale.x -= 0.01;
|
||||
s.scale.y -= 0.01;
|
||||
// s.scale.x -= 0.01;
|
||||
// s.scale.y -= 0.01;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteInfo(s, 32, 32);
|
||||
game.debug.renderSpriteInfo(s2, 32, 320);
|
||||
|
||||
game.debug.renderPoint(s.topLeft, 'rgb(255,0,0)');
|
||||
game.debug.renderPoint(s.topRight, 'rgb(0,255,0)');
|
||||
game.debug.renderPoint(s.bottomLeft, 'rgb(0,0,255)');
|
||||
game.debug.renderPoint(s.bottomRight, 'rgb(255,0,255)');
|
||||
|
||||
game.debug.renderPoint(s2.topLeft, 'rgb(255,0,0)');
|
||||
game.debug.renderPoint(s2.topRight, 'rgb(0,255,0)');
|
||||
game.debug.renderPoint(s2.bottomLeft, 'rgb(0,0,255)');
|
||||
game.debug.renderPoint(s2.bottomRight, 'rgb(255,0,255)');
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
+21
-2
@@ -51,10 +51,29 @@ Phaser.World.prototype = {
|
||||
|
||||
this.camera.update();
|
||||
|
||||
for (var child in this._container.children)
|
||||
var displayObject = this._stage;
|
||||
|
||||
// once the display object hits this. we can break the loop
|
||||
var testObject = displayObject.last._iNext;
|
||||
displayObject = displayObject.first;
|
||||
|
||||
do
|
||||
{
|
||||
this._container.children[child].update();
|
||||
if (!displayObject.visible)
|
||||
{
|
||||
displayObject = displayObject.last._iNext;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (displayObject['update'])
|
||||
{
|
||||
displayObject.update();
|
||||
}
|
||||
|
||||
// count++
|
||||
displayObject = displayObject._iNext;
|
||||
}
|
||||
while(displayObject != testObject)
|
||||
|
||||
},
|
||||
|
||||
|
||||
@@ -140,32 +140,13 @@ Phaser.Sprite.prototype.update = function() {
|
||||
this.position.x = this._x - (this.game.world.camera.x * this.scrollFactor.x);
|
||||
this.position.y = this._y - (this.game.world.camera.y * this.scrollFactor.y);
|
||||
|
||||
// Update the edge points (sx, sy)
|
||||
this.offset.setTo(this.x - (this.anchor.x * this.width), this.y - (this.anchor.y * this.height));
|
||||
// Update the edge points
|
||||
this.offset.setTo(this._x - (this.anchor.x * this.width), this._y - (this.anchor.y * this.height));
|
||||
|
||||
// var sx = s.x - offsetX;
|
||||
// var sy = s.y - offsetY;
|
||||
|
||||
// top left
|
||||
this.getLocalPosition(this.topLeft, this.offset.x, this.offset.y);
|
||||
// var p1 = getLocalPosition(sx, sy, s);
|
||||
|
||||
// top right
|
||||
this.getLocalPosition(this.topRight, this.offset.x + this.width, this.offset.y);
|
||||
// var p2 = getLocalPosition(sx + s.width, sy, s);
|
||||
|
||||
// bottom left
|
||||
this.getLocalPosition(this.bottomLeft, this.offset.x, this.offset.y + this.height);
|
||||
// var p3 = getLocalPosition(sx, sy + s.height, s);
|
||||
|
||||
// bottom right
|
||||
this.getLocalPosition(this.bottomRight, this.offset.x + this.width, this.offset.y + this.height);
|
||||
// var p4 = getLocalPosition(sx + s.width, sy + s.height, s);
|
||||
|
||||
// p1.add(s.x, s.y);
|
||||
// p2.add(s.x, s.y);
|
||||
// p3.add(s.x, s.y);
|
||||
// p4.add(s.x, s.y);
|
||||
|
||||
// this.checkBounds();
|
||||
|
||||
@@ -185,9 +166,8 @@ Phaser.Sprite.prototype.getLocalPosition = function(p, x, y) {
|
||||
|
||||
this._id = 1 / (this._a00 * this._a11 + this._a01 * -this._a10);
|
||||
|
||||
p.x = (this._a11 * this._id * x + -this._a01 * this._id * y + (this._a12 * this._a01 - this._a02 * this._a11) * this._id) * this.scale.x;
|
||||
p.y = (this._a00 * this._id * y + -this._a10 * this._id * x + (-this._a12 * this._a00 + this._a02 * this._a10) * this._id) * this.scale.y;
|
||||
p.add(this.x, this.y);
|
||||
p.x = ((this._a11 * this._id * x + -this._a01 * this._id * y + (this._a12 * this._a01 - this._a02 * this._a11) * this._id) * this.scale.x) + this.x;
|
||||
p.y = ((this._a00 * this._id * y + -this._a10 * this._id * x + (-this._a12 * this._a00 + this._a02 * this._a10) * this._id) * this.scale.y) + this.y;
|
||||
|
||||
return p;
|
||||
|
||||
|
||||
+3
-3
@@ -272,7 +272,7 @@ Phaser.Utils.Debug.prototype = {
|
||||
this.start(x, y, color);
|
||||
|
||||
this.line('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') anchor: ' + sprite.anchor.x + ' x ' + sprite.anchor.y);
|
||||
// this.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
|
||||
this.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
|
||||
// this.line('wx: ' + sprite.worldView.x + ' wy: ' + sprite.worldView.y + ' ww: ' + sprite.worldView.width.toFixed(1) + ' wh: ' + sprite.worldView.height.toFixed(1) + ' wb: ' + sprite.worldView.bottom + ' wr: ' + sprite.worldView.right);
|
||||
// this.line('sx: ' + sprite.scale.x.toFixed(1) + ' sy: ' + sprite.scale.y.toFixed(1));
|
||||
|
||||
@@ -288,8 +288,8 @@ Phaser.Utils.Debug.prototype = {
|
||||
this.line('scale y: ' + sprite.worldTransform[4]);
|
||||
this.line('tx: ' + sprite.worldTransform[2]);
|
||||
this.line('ty: ' + sprite.worldTransform[5]);
|
||||
this.line('skew x: ' + sprite.worldTransform[1]);
|
||||
this.line('skew y: ' + sprite.worldTransform[3]);
|
||||
this.line('skew x: ' + sprite.worldTransform[3]);
|
||||
this.line('skew y: ' + sprite.worldTransform[1]);
|
||||
|
||||
// this.line('tx: ' + sprite.texture.width.toFixed(1) + ' ty: ' + sprite.texture.height.toFixed(1));
|
||||
// this.line('center x: ' + sprite.transform.center.x + ' y: ' + sprite.transform.center.y);
|
||||
|
||||
Reference in New Issue
Block a user