mirror of
https://github.com/wassname/phaser.git
synced 2026-07-30 12:30:07 +08:00
Lots of work on Group and also resolved the issue of the core game loop structure not being quite right.
This commit is contained in:
@@ -22,7 +22,7 @@ Phaser.Physics.Arcade = function (game) {
|
||||
this.OVERLAP_BIAS = 4;
|
||||
this.TILE_OVERLAP = false;
|
||||
|
||||
this.quadTree = null;
|
||||
this.quadTree = new Phaser.QuadTree(this, this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height, this.maxObjects, this.maxLevels);
|
||||
this.quadTreeID = 0;
|
||||
|
||||
// avoid gc spikes by caching these values for re-use
|
||||
@@ -124,6 +124,9 @@ Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
preUpdate: function () {
|
||||
|
||||
// Clear the tree
|
||||
this.quadTree.clear();
|
||||
|
||||
// Create our tree which all of the Physics bodies will add themselves to
|
||||
this.quadTreeID = 0;
|
||||
this.quadTree = new Phaser.QuadTree(this, this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height, this.maxObjects, this.maxLevels);
|
||||
|
||||
@@ -49,7 +49,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
this.immovable = false;
|
||||
this.moves = true;
|
||||
this.rotation = 0;
|
||||
this.allowRotation = false;
|
||||
this.allowRotation = true;
|
||||
this.allowGravity = true;
|
||||
|
||||
this.collideWorldBounds = false;
|
||||
@@ -95,6 +95,10 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.lastX = this.x;
|
||||
this.lastY = this.y;
|
||||
|
||||
this.x = this.sprite.x;
|
||||
this.y = this.sprite.y;
|
||||
this.rotation = this.sprite.angle;
|
||||
|
||||
if (this.moves)
|
||||
{
|
||||
this.game.physics.updateMotion(this);
|
||||
@@ -103,6 +107,11 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.bounds.x = this.x;
|
||||
this.bounds.y = this.y;
|
||||
|
||||
if (this.collideWorldBounds)
|
||||
{
|
||||
this.checkWorldBounds();
|
||||
}
|
||||
|
||||
if (this.allowCollision.none == false && this.sprite.visible && this.sprite.alive)
|
||||
{
|
||||
this.quadTreeIDs = [];
|
||||
@@ -110,6 +119,15 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.game.physics.quadTree.insert(this);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
if (this.allowRotation)
|
||||
{
|
||||
this.sprite.angle = this.rotation;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
checkWorldBounds: function () {
|
||||
@@ -144,18 +162,31 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
postUpdate: function () {
|
||||
|
||||
/*
|
||||
// The State update may (almost certainly?) will had
|
||||
|
||||
if (this.collideWorldBounds)
|
||||
{
|
||||
// Adjust sprite directly?
|
||||
this.checkWorldBounds();
|
||||
}
|
||||
|
||||
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);
|
||||
console.log('pre pu', this.x, this.y);
|
||||
|
||||
// if (this.moves)
|
||||
// {
|
||||
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);
|
||||
// }
|
||||
|
||||
console.log('post pu', this.sprite.x, this.sprite.y);
|
||||
|
||||
if (this.allowRotation)
|
||||
{
|
||||
this.sprite.angle = this.rotation;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user