Jump to content

Spawning enemy


nouse1337
 Share

Recommended Posts

Hi all,

 

I was wondering if anybody could help with my spawning problem? I'd like to spawn enemies at a random location. I'm using a tilemap for my player to walk around. In this tilemap are element with which the player and enemies collide. How could I make sure an enemy isn't spawned on top of the element that collides with the enemy ?

 

Thanks in advance

Link to comment
Share on other sites

well you have to (somehow) find out if there is something at the spawn point... 

 

using p2 physics you could do something like the following:

var hitObjects = game.physics.p2.hitTest({x: xCoord, y: yCoord});

this would populate an array "hitObjects" with all p2 bodies under the given coordinates

if this array isn't empty you should try another location..  

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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