valueerror Posted June 18, 2014 Share Posted June 18, 2014 @titmael.. so the only thing that stops you from using collisiongroups (which will be the way i'm going to implement my hammer ... yes ;-) i need a hammer too..) is that you dont know yet how to get your objects to collide with the tilemap layers then... Link to comment Share on other sites More sharing options...
titmael Posted June 19, 2014 Author Share Posted June 19, 2014 @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 More sharing options...
valueerror Posted June 19, 2014 Share Posted June 19, 2014 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 collisionGroupplayer.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 More sharing options...
titmael Posted June 19, 2014 Author Share Posted June 19, 2014 Thx for this piece of code, I'll check later if I move on with collision groups Link to comment Share on other sites More sharing options...
Recommended Posts