Sign in to follow this  
nouse1337

Spawning enemy

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

Share this post


Link to post
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..  

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.