Jump to content

Collision with a member of a group and a sprite


lukeSturgess
 Share

Recommended Posts

Looking through some of the other posts about this I couldn't manage to get mine to work. I've got: 

 

game.physics.arcade.collide(enemy1, world.player_spr, checkCollisionPlayer, null, this);

 

function checkCollisionPlayer(thePlayer_spr, other_spr) {
        other_spr.kill();
}
 
where enemy1 is the group, player_spr is my player sprite and checkCollisionPlayer is my collision handler and I want the sprite from the group to be destroyed if they hit the player.
 
 
I've tried other_spr.destroy(); as well but the sprites in the group just walk straight past my player no matter what.
 
Thanks in advance.
 
 
Link to comment
Share on other sites

The problem is that they're not colliding? And it's not calling your checkCollisionPlayer function? If you put a "console.log('catpants');" statement at the beginning of your checkCollisionPlayer you can see if it's getting called at all.

 

I bet your enemies aren't really in that group and your collision handler isn't being called.

Link to comment
Share on other sites

So I sorted that problem out, I was adding the enemy spirtes to a world layer and that was confusing things. But, now that I'm not adding them to the enemy layer they are colliding and destroying but they are spawning in under the floor layer so they can't be seen. Is there a way for me to set their z coordinate to above the ground layer?

Link to comment
Share on other sites

So I sorted that problem out, I was adding the enemy spirtes to a world layer and that was confusing things. But, now that I'm not adding them to the enemy layer they are colliding and destroying but they are spawning in under the floor layer so they can't be seen. Is there a way for me to set their z coordinate to above the ground layer?

 

You want to draw your layers in order.

Create the ground layer first, after that create groups that go on top of the ground layer, such as enemies/players/etc. Groups are rendered in the order they are created. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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