Jump to content

Group collide callback not working


Recommended Posts


I'trying to make a callback function between two groups, but it's not working and I don't know why.



Heres the code :

playerCollisionGroup = game.physics.p2.createCollisionGroup();for (var k in jsonData){   jsonData[k].body.setCollisionGroup(playerCollisionGroup);   setCollisionWithColliders(jsonData[k]);   jsonData[k].body.collides([playerCollisionGroup,collisionGroup]);}function setCollisionWithColliders(player){   for (var k in obj.tiles)   {      if (tiles[k].body)          tiles[k].body.collides(obj.playerCollisionGroup);    }    player.body.collides([playerCollisionGroup,collisionGroup],collisionCallback,this);}function collisionCallback(body1,body2){    console.log('yay!');}

all of this code it is in the create function!


Any ideas of what's wrong? D:


Link to comment
Share on other sites

i guess you did activate p2 physics.. (otherwise your console would be full of errors)  so if there are no errors (i have to guess because you only provided a snippet of the code)

i guess you forgot to activate the collision events...  rich said they are to expensive to be activated as a default so you have to do it..

 game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.setImpactEvents(true);

if thats not it...  where do you assign the collision group to the tiles? i don't see it...


and one other thing..


jsonData[k]  gets the player collision group.. so it is the player ?  


therefor you define the objects to collide with twice..  one time in the for loop without callback and one time in the function with callback..  i had a similar problem once and i had to remove the line without a callback to make the callback work..   




Link to comment
Share on other sites

Dammit, it was the the 


I hate those little flags that manage all the things D:

But, its the cost of optimization, so it's ok


yes, jsonData[k] it`s an objects that contains the player in the game


I defined twice in a desperate way to make the callback works hahah


But thanks, it resolved the problem   o/

Link to comment
Share on other sites


  • Recently Browsing   0 members

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