mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 04:33:31 +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
|
||||
|
||||
var Class = require('../../utils/Class');
|
||||
var Components = require('./Components');
|
||||
var COLLIDES = require('./COLLIDES');
|
||||
var GetVelocity = require('./GetVelocity');
|
||||
var TYPE = require('./TYPE');
|
||||
|
@ -29,6 +28,8 @@ var Body = new Class({
|
|||
|
||||
this.parent;
|
||||
|
||||
this.id = world.getNextID();
|
||||
|
||||
this.name = '';
|
||||
|
||||
this.size = { x: sx, y: sy };
|
||||
|
|
|
@ -26,15 +26,12 @@ var CollisionMap = new Class({
|
|||
// Set up the trace-result
|
||||
var res = {
|
||||
collision: { x: false, y: false, slope: false },
|
||||
pos: { x: x, y: y },
|
||||
pos: { x: x + vx, y: y + vy },
|
||||
tile: { x: 0, y: 0 }
|
||||
};
|
||||
|
||||
if (!this.data)
|
||||
{
|
||||
res.pos.x += vx;
|
||||
res.pos.y += vy;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -80,13 +77,13 @@ var CollisionMap = new Class({
|
|||
|
||||
step: function (res, x, y, vx, vy, width, height, rvx, rvy, step)
|
||||
{
|
||||
res.pos.x += vx;
|
||||
res.pos.y += vy;
|
||||
// res.pos.x += vx;
|
||||
// res.pos.y += vy;
|
||||
|
||||
if (window.dumpit)
|
||||
{
|
||||
console.log('STEP', res.pos.x, res.pos.y, 'VX', vx, 'VY', vy, 'step', step);
|
||||
}
|
||||
// if (window.dumpit)
|
||||
// {
|
||||
// console.log('STEP', res.pos.x, res.pos.y, 'VX', vx, 'VY', vy, 'step', step);
|
||||
// }
|
||||
|
||||
var t = 0;
|
||||
var tilesize = this.tilesize;
|
||||
|
@ -144,10 +141,10 @@ var CollisionMap = new Class({
|
|||
|
||||
t = this.data[tileY][tileX];
|
||||
|
||||
if (window.debugslopes)
|
||||
{
|
||||
console.log('Tile at', tileX, 'x', tileY, '=', t);
|
||||
}
|
||||
// if (window.debugslopes)
|
||||
// {
|
||||
// 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)))
|
||||
{
|
||||
|
|
|
@ -29,6 +29,13 @@ var World = new Class({
|
|||
this.collisionMap = new CollisionMap();
|
||||
|
||||
this.delta = 0;
|
||||
|
||||
this._lastId = 0;
|
||||
},
|
||||
|
||||
getNextID: function ()
|
||||
{
|
||||
return this._lastId++;
|
||||
},
|
||||
|
||||
create: function (x, y, sizeX, sizeY)
|
||||
|
@ -55,6 +62,7 @@ var World = new Class({
|
|||
// Update all bodies
|
||||
|
||||
var i;
|
||||
var body;
|
||||
var bodies = this.bodies.entries;
|
||||
var len = bodies.length;
|
||||
var hash = {};
|
||||
|
@ -64,7 +72,7 @@ var World = new Class({
|
|||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
var body = bodies[i];
|
||||
body = bodies[i];
|
||||
|
||||
if (body.enabled)
|
||||
{
|
||||
|
@ -76,13 +84,9 @@ var World = new Class({
|
|||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
var body = bodies[i];
|
||||
body = bodies[i];
|
||||
|
||||
if (body.skipHash())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
if (!body.skipHash())
|
||||
{
|
||||
this.checkHash(body, hash, size);
|
||||
}
|
||||
|
@ -147,7 +151,6 @@ var World = new Class({
|
|||
|
||||
if (bodyA.collides && bodyB.collides && bodyA.collides + bodyB.collides > COLLIDES.ACTIVE)
|
||||
{
|
||||
// console.log('solve');
|
||||
Solver(this, bodyA, bodyB);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue