How do I control spawning locations

Get help using Construct 2

Post » Tue Nov 04, 2014 9:58 pm

I want to spawn a sprite at a random place on my layout - however I don't want the sprite to be created within 25 pixels of any existing sprite; how would I go about this?

Cheers guys
B
59
S
21
G
9
Posts: 641
Reputation: 9,787

Post » Wed Nov 05, 2014 1:19 am

Put all of the sprites into a family.

Spawn an invisible round sprite however you would randomly.
Give the invisible sprite fade behavior with it set destroy when fade is finished.
Choose the fade out time in properties.
Then create dual condition:

Invisible sprite on created >
Is overlapping > Family > Spawn > Whatever sprite
Else > Spawn an invisible sprite however you would randomly again

(x) being inverted

If the Invisible sprite is not overlapping of the existing family sprite, then you new sprite gets spawned, if not, nothing gets spawned and it tries again. Remember to set the invisible circle sprites collision in the circle shape.

You could create a function to create the Invisible sprite. It's the invisible sprite that's used to create the real sprite that you want to spawn and then it is destroyed, never being seen.

Hope this helps
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,283


Return to How do I....?

Who is online

Users browsing this forum: David181, evillair and 58 guests