Jump to content

game.physics.p2.removeSpring strange behaviour - can not remove single spring


valueerror
 Share

Recommended Posts

while i can do the following for constraints:

var allConstraints = game.physics.p2.getConstraints();    if (allConstraints.length > 0){        for (i=0; i<=allConstraints.length; i++){ game.physics.p2.removeConstraint(allConstraints[i]);}    }

it seems that springs work different although the documentation says it works exactly the same way:

 var allSprings = game.physics.p2.getSprings();    if (allSprings.length > 0){         game.physics.p2.removeSpring(allSprings);    }

removeSpring does not take A spring .. it takes a spring array...   so how would i remove a single spring then?

Link to comment
Share on other sites

According to the phaser source:

World.prototype.removeSpring = function(s){    var idx = this.springs.indexOf(s);    if(idx===-1){        Utils.splice(this.springs,idx,1);    }};
 /**    * Removes a Spring from the world.    *    * @method Phaser.Physics.P2#removeSpring    * @param {Phaser.Physics.P2.Spring} spring - The Spring to remove from the World.    * @return {Phaser.Physics.P2.Spring} The Spring that was removed.    */    removeSpring: function (spring) {        this.world.removeSpring(spring);        this.onSpringRemoved.dispatch(spring);        return spring;    }
Looks like a bug. It should be  "if(idx!==-1){". Other than this bug, it behaves the same as contraints. lol.
Link to comment
Share on other sites

  • 4 weeks later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...