druphoria Posted July 14, 2014 Share Posted July 14, 2014 I'm trying to write code to make my enemies change the direction they are moving in when they run into an object or a wall. Right now I have a single tilemap - I tried to create a second layer (where i put everything that could be collided with) within this tilemap and change the enemy direction in a callback function when the enemies collide with this second layer, but I discovered that Phaser currently only supports collision with one layer. What would be the recommended way to do this (aside from creating a second tilemap)? Link to comment Share on other sites More sharing options...
Heppell08 Posted July 14, 2014 Share Posted July 14, 2014 you can use tile functions on contact. So if an enemy were to touch the tile you specify then it will fire a function. So you can change directions/speed/health/damage you name it, it can be done.There is an example here: http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=tile+callbacks.js&t=tile%20callbacks Link to comment Share on other sites More sharing options...
druphoria Posted July 14, 2014 Author Share Posted July 14, 2014 Oh awesome - thanks. That will definitely be handy. I actually ended up implementing another solution last night - basically I stored the enemy's previous x position and check within the "update" method if the x position has changed. If it hasn't changed since the last time update was called, then I change the direction. Great to know that there is a way to have callback on specific tiles though. Link to comment Share on other sites More sharing options...
druphoria Posted July 14, 2014 Author Share Posted July 14, 2014 Actually I might have to implement the tile callbacks either way, since I just realized that with my algorithm the bad guys will walk right into holes. Link to comment Share on other sites More sharing options...
Recommended Posts