Jump to content

physics.p2 increase body


mrdotb
 Share

Recommended Posts

Hello,

I want to increase my player body.

this.physics.p2.enable(this.player, false);//I want to increase this bodythis.player.body.setCircle(50);this.player.body.setCollisionGroup(this.playerCollisionGroup);this.player.body.collides(this.ballCollisionGroup, this.hitBall, this);hitBall: function (player, ball) {                //I try this way but I'm loosing my CollisionGroup. How to do it ?        player.sprite.body.setCircle(100);        }//thanks
Link to comment
Share on other sites

setCircle(100)  is like removing the physics body with all it's configurations and then installing a new one..   the easiest way to go would be to reapply the other settings after setCircle :)

this.player.body.setCircle(50);this.player.body.setCollisionGroup(this.playerCollisionGroup);this.player.body.collides(this.ballCollisionGroup, this.hitBall, this);hitBall: function (player, ball) {       player.sprite.body.setCircle(100);       player.body.setCollisionGroup(playerCollisionGroup);       player.body.collides(ballCollisionGroup, hitBall, this);}
Link to comment
Share on other sites

Thank you valueerror. I though this solution but don't try it. Here is something close to my final code.

this.playerBodySize = 50;this.player.body.setCircle(this.playerBodySize);this.player.body.setCollisionGroup(this.playerCollisionGroup);this.player.body.collides(this.ballCollisionGroup, this.hitBall, this);hitBall: function (player, ball) {       this.playerBodySize += 10;       player.sprite.body.setCircle(this.playerBodySize);       player.body.setCollisionGroup(playerCollisionGroup);       player.body.collides(ballCollisionGroup, hitBall, this);}

You can check the result. http://games.baptistechaleil.fr/batcattest/

Link to comment
Share on other sites

I have a question, are the collisions groups safe to use in P2 Physics? From their documentation I understand that each collision group is actually a bitmap. If I have 100 bullets (that move each frame) in a collision group and 100 enemies that move each frame, in another collision group, would it be ok to use collision groups? Or simply use onBeginContact on each body and filter based on body.sprite?

Link to comment
Share on other sites

in my last game i completely relied on onBeginContact events because someone told me that collisionGroups (which need impact events to be enabled) are a little bit more expensive..  in several tests i couldn't make out any difference so i'm probably going to use collisiongroups again the next time because they are IMHO so much easier to handle.. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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