mirror of
https://github.com/photonstorm/phaser
synced 2024-11-21 20:23:19 +00:00
Testing sleep static fixes
This commit is contained in:
parent
bd67ed38a5
commit
f0d5280cf8
2 changed files with 44 additions and 13 deletions
|
@ -28,13 +28,13 @@ var Body = require('./Body');
|
|||
* @return {composite} A new composite
|
||||
*/
|
||||
Composite.create = function(options) {
|
||||
return Common.extend({
|
||||
return Common.extend({
|
||||
id: Common.nextId(),
|
||||
type: 'composite',
|
||||
parent: null,
|
||||
isModified: false,
|
||||
bodies: [],
|
||||
constraints: [],
|
||||
bodies: [],
|
||||
constraints: [],
|
||||
composites: [],
|
||||
label: 'Composite',
|
||||
plugin: {},
|
||||
|
@ -47,7 +47,7 @@ var Body = require('./Body');
|
|||
};
|
||||
|
||||
/**
|
||||
* Sets the composite's `isModified` flag.
|
||||
* Sets the composite's `isModified` flag.
|
||||
* If `updateParents` is true, all parents will be set (default: false).
|
||||
* If `updateChildren` is true, all children will be set (default: false).
|
||||
* @method setModified
|
||||
|
@ -246,6 +246,10 @@ var Body = require('./Body');
|
|||
var position = Common.indexOf(composite.bodies, body);
|
||||
if (position !== -1) {
|
||||
Composite.removeBodyAt(composite, position);
|
||||
|
||||
// remove sleeping to allow pair removal
|
||||
body.isSleeping = false;
|
||||
body.sleepCounter = 0;
|
||||
}
|
||||
|
||||
if (deep) {
|
||||
|
@ -337,7 +341,7 @@ var Body = require('./Body');
|
|||
Composite.clear(composite.composites[i], keepStatic, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (keepStatic) {
|
||||
composite.bodies = composite.bodies.filter(function(body) { return body.isStatic; });
|
||||
} else {
|
||||
|
@ -448,8 +452,8 @@ var Body = require('./Body');
|
|||
if (!objects)
|
||||
return null;
|
||||
|
||||
object = objects.filter(function(object) {
|
||||
return object.id.toString() === id.toString();
|
||||
object = objects.filter(function(object) {
|
||||
return object.id.toString() === id.toString();
|
||||
});
|
||||
|
||||
return object.length === 0 ? null : object[0];
|
||||
|
@ -488,7 +492,7 @@ var Body = require('./Body');
|
|||
};
|
||||
|
||||
/**
|
||||
* Translates all children in the composite by a given vector relative to their current positions,
|
||||
* Translates all children in the composite by a given vector relative to their current positions,
|
||||
* without imparting any velocity.
|
||||
* @method translate
|
||||
* @param {composite} composite
|
||||
|
@ -522,7 +526,7 @@ var Body = require('./Body');
|
|||
var body = bodies[i],
|
||||
dx = body.position.x - point.x,
|
||||
dy = body.position.y - point.y;
|
||||
|
||||
|
||||
Body.setPosition(body, {
|
||||
x: point.x + (dx * cos - dy * sin),
|
||||
y: point.y + (dx * sin + dy * cos)
|
||||
|
@ -550,7 +554,7 @@ var Body = require('./Body');
|
|||
var body = bodies[i],
|
||||
dx = body.position.x - point.x,
|
||||
dy = body.position.y - point.y;
|
||||
|
||||
|
||||
Body.setPosition(body, {
|
||||
x: point.x + dx * scaleX,
|
||||
y: point.y + dy * scaleY
|
||||
|
|
|
@ -53,6 +53,8 @@ var Common = require('../core/Common');
|
|||
collisionActiveIndex = 0,
|
||||
collision,
|
||||
pair,
|
||||
bodyA,
|
||||
bodyB,
|
||||
i;
|
||||
|
||||
for (i = 0; i < collisionsLength; i++) {
|
||||
|
@ -90,11 +92,36 @@ var Common = require('../core/Common');
|
|||
pair = pairsList[i];
|
||||
|
||||
if (pair.timeUpdated < timestamp) {
|
||||
pairSetActive(pair, false, timestamp);
|
||||
collisionEnd[collisionEndIndex++] = pair;
|
||||
|
||||
bodyA = pair.collision.bodyA;
|
||||
bodyB = pair.collision.bodyB;
|
||||
|
||||
// if ((bodyA.isSleeping && bodyB.isSleeping) || bodyA.isStatic || bodyB.isStatic)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// keep pair if it is sleeping but not both static
|
||||
// if ((bodyA.isSleeping || bodyA.isStatic) || (bodyB.isSleeping || bodyB.isStatic) && !(bodyA.isStatic && bodyB.isStatic)) {
|
||||
// pairSetActive(pair, true, timestamp);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// pairSetActive(pair, false, timestamp);
|
||||
// collisionEnd[collisionEndIndex++] = pair;
|
||||
|
||||
// keep pair if it is sleeping but not both static
|
||||
// if ((bodyA.isSleeping || bodyA.isStatic) && (bodyB.isSleeping || bodyB.isStatic)
|
||||
// && !(bodyA.isStatic && bodyB.isStatic)) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// remove inactive pairs
|
||||
if (!pair.collision.bodyA.isSleeping && !pair.collision.bodyB.isSleeping) {
|
||||
// if (!bodyA.isSleeping && !bodyB.isSleeping && !bodyA.isStatic && !bodyB.isStatic) {
|
||||
if ((!bodyA.isSleeping || !bodyA.isStatic) && (!bodyB.isSleeping || !bodyB.isStatic)) {
|
||||
console.log('deleted pair', bodyA, bodyB);
|
||||
pairSetActive(pair, false, timestamp);
|
||||
collisionEnd[collisionEndIndex++] = pair;
|
||||
delete pairsTable[pair.id];
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue