mrdotb Posted February 9, 2015 Share Posted February 9, 2015 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 More sharing options...
hollowdoor Posted February 9, 2015 Share Posted February 9, 2015 Maybe this will help Can't scale sprite body using tween Link to comment Share on other sites More sharing options...
valueerror Posted February 10, 2015 Share Posted February 10, 2015 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 More sharing options...
mrdotb Posted February 10, 2015 Author Share Posted February 10, 2015 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 More sharing options...
tips4design Posted February 11, 2015 Share Posted February 11, 2015 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 More sharing options...
valueerror Posted February 11, 2015 Share Posted February 11, 2015 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.. tips4design 1 Link to comment Share on other sites More sharing options...
Recommended Posts