Jump to content

Player with a hammer


titmael
 Share

Recommended Posts

@valueerror : yes but not only. Finally my collisionHandler allows me to handle collisions for all my objects and their state. For example a dead enemy doesn't collide with player or alive enemies but still collide tilemap

Link to comment
Share on other sites

you can do all this with collisiongroups too of course..  do you have impactEvents enabled  ( if not i would leave everything the way it is because of a performance advantage without impactEvents.. if you have it enabled you have this performance drain anyways  so you could use collisionGroups - it wouldn't change much but give you a more precise way to handle what collides with what..

 

just for the case you need it at some point ... here is the code how you can assign collisiongroups and materials to a tilemap layer:

layerenemy = map.createLayer('enemylayer');  // create layermap.setCollisionByExclusion([0],true, layerenemy);   // setup which tiles should collide (in that case all)layerenemy_tiles = game.physics.p2.convertTilemap(map, layerenemy);  // this creates an array of phyiscsbodies for (i=0; i<layerenemy_tiles.length; i++){        layerenemy_tiles[i].setCollisionGroup(enemyGroundCG);        layerenemy_tiles[i].collides([playerCG]);        layerenemy_tiles[i].setMaterial(groundMaterial); }

now my player can collide with the enemylayer's collisionGroup

player.body.setCollisionGroup(playerCG);   // set collision groupplayer.body.collides([enemyGroundCG]);   // collide with whatplayer.body.createGroupCallback(enemyGroundCG, playerHit, this);  // what happens when they collide ( playerHit() )

that way your hammer and your player could be in different collisiongroups that do not collide with each other but both of them would collide with enemies and maybe have different callbacks..  in the callback you could still decide what to do with alive or dead enemies...

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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