spencerTL Posted July 26, 2014 Share Posted July 26, 2014 I have been having trouble removing a P2 spring once created and could only find this github thread about it where it remained unresolved. https://github.com/photonstorm/phaser/issues/974 After some experimenting I have found that creating the spring as shown in the examples and docs results in a spring that I can't remove but by using a different creation method it can be removed. For eg. var spr = this.game.physics.p2.createSpring(b1.body, b2.body, 150, 0.15, 0.05); console.log("getSprings():"); console.log(this.game.physics.p2.world.springs.length) //returns 1 this.game.physics.p2.removeSpring(spr); console.log("b getSprings():"); console.log(this.game.physics.p2.world.springs.length) //returns 1the spring just won't go away. EDIT:I've removed a solution that wasn't a solution in the end. Link to comment Share on other sites More sharing options...
spencerTL Posted July 26, 2014 Author Share Posted July 26, 2014 Turns out I spoke too soon. This isn't a solution. Console shows springs added and removed correctly but, if the spring isn't removed it errors. Any suggestions? Link to comment Share on other sites More sharing options...
spencerTL Posted July 26, 2014 Author Share Posted July 26, 2014 I think I've genuinely got it this time. To remove the spring, its parent needs to be passed in removeSpring method. I can't say I quite understand this, nor why the getSprings() method produces an array of nulls equal in length to the number of springs but I've always been slow on the uptake with physics systems. My solution://assuming P2 physics all set up first and two sprites with bodies: b1 and b2.//add the springvar spr = this.game.physics.p2.createSpring(b1.body, b2.body, 150, 0.15, 0.05);//remove the springthis.game.physics.p2.world.removeSpring(spr.parent);Could anyone explain why this works this way or offer a better way? Link to comment Share on other sites More sharing options...
valueerror Posted July 28, 2014 Share Posted July 28, 2014 well.. IMHO this shouldn't work.. when i create a constraint for example i do the following:swordRC = game.physics.p2.createRevoluteConstraint(sword , [0,0],player, [0,8], 10000and to remove the constraint of course:game.physics.p2.removeConstraint(swordRC);the parent of the swordRC is my game world... Link to comment Share on other sites More sharing options...
valueerror Posted September 2, 2014 Share Posted September 2, 2014 oh.. this must be because of the this bug here https://github.com/photonstorm/phaser/issues/1134 Link to comment Share on other sites More sharing options...
Recommended Posts