mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 21:53:59 +00:00
Body.id was never being assigned, which caused the spatial hash checks to fail, leading to all kinds of weird results. Hours spent debugging this, only for it to be something so simple *facepalm*
This commit is contained in:
parent
ff9534a14a
commit
244e6535b5
3 changed files with 24 additions and 23 deletions
|
@ -1,7 +1,6 @@
|
||||||
// Phaser.Physics.Impact.Body
|
// Phaser.Physics.Impact.Body
|
||||||
|
|
||||||
var Class = require('../../utils/Class');
|
var Class = require('../../utils/Class');
|
||||||
var Components = require('./Components');
|
|
||||||
var COLLIDES = require('./COLLIDES');
|
var COLLIDES = require('./COLLIDES');
|
||||||
var GetVelocity = require('./GetVelocity');
|
var GetVelocity = require('./GetVelocity');
|
||||||
var TYPE = require('./TYPE');
|
var TYPE = require('./TYPE');
|
||||||
|
@ -29,6 +28,8 @@ var Body = new Class({
|
||||||
|
|
||||||
this.parent;
|
this.parent;
|
||||||
|
|
||||||
|
this.id = world.getNextID();
|
||||||
|
|
||||||
this.name = '';
|
this.name = '';
|
||||||
|
|
||||||
this.size = { x: sx, y: sy };
|
this.size = { x: sx, y: sy };
|
||||||
|
|
|
@ -26,15 +26,12 @@ var CollisionMap = new Class({
|
||||||
// Set up the trace-result
|
// Set up the trace-result
|
||||||
var res = {
|
var res = {
|
||||||
collision: { x: false, y: false, slope: false },
|
collision: { x: false, y: false, slope: false },
|
||||||
pos: { x: x, y: y },
|
pos: { x: x + vx, y: y + vy },
|
||||||
tile: { x: 0, y: 0 }
|
tile: { x: 0, y: 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this.data)
|
if (!this.data)
|
||||||
{
|
{
|
||||||
res.pos.x += vx;
|
|
||||||
res.pos.y += vy;
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,13 +77,13 @@ var CollisionMap = new Class({
|
||||||
|
|
||||||
step: function (res, x, y, vx, vy, width, height, rvx, rvy, step)
|
step: function (res, x, y, vx, vy, width, height, rvx, rvy, step)
|
||||||
{
|
{
|
||||||
res.pos.x += vx;
|
// res.pos.x += vx;
|
||||||
res.pos.y += vy;
|
// res.pos.y += vy;
|
||||||
|
|
||||||
if (window.dumpit)
|
// if (window.dumpit)
|
||||||
{
|
// {
|
||||||
console.log('STEP', res.pos.x, res.pos.y, 'VX', vx, 'VY', vy, 'step', step);
|
// console.log('STEP', res.pos.x, res.pos.y, 'VX', vx, 'VY', vy, 'step', step);
|
||||||
}
|
// }
|
||||||
|
|
||||||
var t = 0;
|
var t = 0;
|
||||||
var tilesize = this.tilesize;
|
var tilesize = this.tilesize;
|
||||||
|
@ -144,10 +141,10 @@ var CollisionMap = new Class({
|
||||||
|
|
||||||
t = this.data[tileY][tileX];
|
t = this.data[tileY][tileX];
|
||||||
|
|
||||||
if (window.debugslopes)
|
// if (window.debugslopes)
|
||||||
{
|
// {
|
||||||
console.log('Tile at', tileX, 'x', tileY, '=', t);
|
// console.log('Tile at', tileX, 'x', tileY, '=', t);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (t === 1 || t > this.lastSlope || (t > 1 && this.checkDef(res, t, x, y, rvx, rvy, width, height, tileX, tileY)))
|
if (t === 1 || t > this.lastSlope || (t > 1 && this.checkDef(res, t, x, y, rvx, rvy, width, height, tileX, tileY)))
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,13 @@ var World = new Class({
|
||||||
this.collisionMap = new CollisionMap();
|
this.collisionMap = new CollisionMap();
|
||||||
|
|
||||||
this.delta = 0;
|
this.delta = 0;
|
||||||
|
|
||||||
|
this._lastId = 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
getNextID: function ()
|
||||||
|
{
|
||||||
|
return this._lastId++;
|
||||||
},
|
},
|
||||||
|
|
||||||
create: function (x, y, sizeX, sizeY)
|
create: function (x, y, sizeX, sizeY)
|
||||||
|
@ -55,6 +62,7 @@ var World = new Class({
|
||||||
// Update all bodies
|
// Update all bodies
|
||||||
|
|
||||||
var i;
|
var i;
|
||||||
|
var body;
|
||||||
var bodies = this.bodies.entries;
|
var bodies = this.bodies.entries;
|
||||||
var len = bodies.length;
|
var len = bodies.length;
|
||||||
var hash = {};
|
var hash = {};
|
||||||
|
@ -64,7 +72,7 @@ var World = new Class({
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
var body = bodies[i];
|
body = bodies[i];
|
||||||
|
|
||||||
if (body.enabled)
|
if (body.enabled)
|
||||||
{
|
{
|
||||||
|
@ -76,13 +84,9 @@ var World = new Class({
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
var body = bodies[i];
|
body = bodies[i];
|
||||||
|
|
||||||
if (body.skipHash())
|
if (!body.skipHash())
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
this.checkHash(body, hash, size);
|
this.checkHash(body, hash, size);
|
||||||
}
|
}
|
||||||
|
@ -147,7 +151,6 @@ var World = new Class({
|
||||||
|
|
||||||
if (bodyA.collides && bodyB.collides && bodyA.collides + bodyB.collides > COLLIDES.ACTIVE)
|
if (bodyA.collides && bodyB.collides && bodyA.collides + bodyB.collides > COLLIDES.ACTIVE)
|
||||||
{
|
{
|
||||||
// console.log('solve');
|
|
||||||
Solver(this, bodyA, bodyB);
|
Solver(this, bodyA, bodyB);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue