mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
merge tumult:old_ie_fixes + tweaks
This commit is contained in:
commit
6e1ab9a24c
5 changed files with 26 additions and 8 deletions
|
@ -166,7 +166,7 @@ var Composite = {};
|
|||
* @return {composite} The original compositeA with the composite removed
|
||||
*/
|
||||
Composite.removeComposite = function(compositeA, compositeB, deep) {
|
||||
var position = compositeA.composites.indexOf(compositeB);
|
||||
var position = Common.indexOf(compositeA.composites, compositeB);
|
||||
if (position !== -1) {
|
||||
Composite.removeCompositeAt(compositeA, position);
|
||||
Composite.setModified(compositeA, true, true, false);
|
||||
|
@ -219,7 +219,7 @@ var Composite = {};
|
|||
* @return {composite} The original composite with the body removed
|
||||
*/
|
||||
Composite.removeBody = function(composite, body, deep) {
|
||||
var position = composite.bodies.indexOf(body);
|
||||
var position = Common.indexOf(composite.bodies, body);
|
||||
if (position !== -1) {
|
||||
Composite.removeBodyAt(composite, position);
|
||||
Composite.setModified(composite, true, true, false);
|
||||
|
@ -272,7 +272,7 @@ var Composite = {};
|
|||
* @return {composite} The original composite with the constraint removed
|
||||
*/
|
||||
Composite.removeConstraint = function(composite, constraint, deep) {
|
||||
var position = composite.constraints.indexOf(constraint);
|
||||
var position = Common.indexOf(composite.constraints, constraint);
|
||||
if (position !== -1) {
|
||||
Composite.removeConstraintAt(composite, position);
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ var Grid = {};
|
|||
*/
|
||||
var _bucketRemoveBody = function(grid, bucket, body) {
|
||||
// remove from bucket
|
||||
bucket.splice(bucket.indexOf(body), 1);
|
||||
bucket.splice(Common.indexOf(bucket, body), 1);
|
||||
|
||||
// update pair counts
|
||||
for (var i = 0; i < bucket.length; i++) {
|
||||
|
|
|
@ -85,7 +85,7 @@ var Pairs = {};
|
|||
// deactivate previously active pairs that are now inactive
|
||||
for (i = 0; i < pairsList.length; i++) {
|
||||
pair = pairsList[i];
|
||||
if (pair.isActive && activePairIds.indexOf(pair.id) === -1) {
|
||||
if (pair.isActive && Common.indexOf(activePairIds, pair.id) === -1) {
|
||||
Pair.setActive(pair, false, timestamp);
|
||||
collisionEnd.push(pair);
|
||||
}
|
||||
|
|
|
@ -281,6 +281,24 @@ var Common = {};
|
|||
return Common._nextId++;
|
||||
};
|
||||
|
||||
/**
|
||||
* A cross browser compatible indexOf implementation
|
||||
* @method indexOf
|
||||
* @param {array} haystack
|
||||
* @param {object} needle
|
||||
*/
|
||||
Common.indexOf = function(haystack, needle) {
|
||||
if (haystack.indexOf)
|
||||
return haystack.indexOf(needle);
|
||||
|
||||
for (var i = 0; i < haystack.length; i++) {
|
||||
if (haystack[i] === needle)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
var _seededRandom = function() {
|
||||
// https://gist.github.com/ngryman/3830489
|
||||
Common._seed = (Common._seed * 9301 + 49297) % 233280;
|
||||
|
|
|
@ -261,7 +261,7 @@ var RenderPixi = {};
|
|||
}
|
||||
|
||||
// add to scene graph if not already there
|
||||
if (container.children.indexOf(primitive) === -1)
|
||||
if (Common.indexOf(container.children, primitive) === -1)
|
||||
container.addChild(primitive);
|
||||
|
||||
// render the constraint on every update, since they can change dynamically
|
||||
|
@ -307,7 +307,7 @@ var RenderPixi = {};
|
|||
sprite = render.sprites[spriteId] = _createBodySprite(render, body);
|
||||
|
||||
// add to scene graph if not already there
|
||||
if (spriteBatch.children.indexOf(sprite) === -1)
|
||||
if (Common.indexOf(spriteBatch.children, sprite) === -1)
|
||||
spriteBatch.addChild(sprite);
|
||||
|
||||
// update body sprite
|
||||
|
@ -326,7 +326,7 @@ var RenderPixi = {};
|
|||
}
|
||||
|
||||
// add to scene graph if not already there
|
||||
if (container.children.indexOf(primitive) === -1)
|
||||
if (Common.indexOf(container.children, primitive) === -1)
|
||||
container.addChild(primitive);
|
||||
|
||||
// update body primitive
|
||||
|
|
Loading…
Reference in a new issue