Don't create sprite if already exists at location

Get help using Construct 2

Post » Tue Dec 31, 2013 2:18 am

I am creating a wandering monster feature in my game and would like to check for a random monster every X seconds, and based on a random value, if fails, then create a monster at a random location.

The player follows the path of a ground tile ... so I want to create a monster at random ground tile location, which I am able to do. What I want to do is prevent the creation of monster if a monster sprite already exists there.

What would be the best way to do this?
B
17
S
3
Posts: 33
Reputation: 1,666

Post » Tue Dec 31, 2013 2:24 am

@phatkidsoftware You can use an invisible Sprite to position at random location and check if it overlaps with the monster.
P.S. 2 sprites that are side by side on a pixel level WILL trigger an overlap condition in C2. Make sure that the Sprite is 1-2 px smaller than the tile, so is no chance of touching the edge of the monster. (I found that the hard way)

TIP: if you want to use a "snap to grid" use the formula:
X-X%gridSizeCipriux2013-12-31 02:31:22
B
81
S
21
G
23
Posts: 515
Reputation: 18,702

Post » Tue Dec 31, 2013 2:42 am

That worked! I just created an invisible sprite called Positioner, and moved it to the spot that I wanted to creating something at, and tested for overlap, if there was none, I spawned the new object.
B
17
S
3
Posts: 33
Reputation: 1,666


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests