Random Spawn without overlapping

0 favourites
  • 4 posts
From the Asset Store
In this template the music plays without looping in your game
  • Hi, can anyone help me with this?

    I have one sprite and i want to keep spawning the same sprite randomly on the screen, how could I avoid them spawning where it's another instance of the sprite?

    I've tried to check collisions when the sprite is created, and if true move the sprite to a new random location, but it either moves both colliding sprites or does not move any.

    Hope you can help me! :)

  • Maybe it will help you: just check the sprite colision and if it true - just destroy one of them.

  • I believe the reason your approach is not working is because it's 'picking' both sprites rather than just one. Here's how you might fix it. Let's assume your sprite is called 'Sprite'.

    First create a family called 'SpawnedObjects' and add 'Sprite' to it.

    Then, in your events, check to see if the newly created object 'Sprite' is overlapping any 'SpawnedObjects'. If it is, then position 'Sprite' to a new location.

    This way, you've differentiated the created sprite from the already existing one. You've identified 'Sprite' as the newly created one and 'SpawnedObjects' as the existing one. Simply move 'Sprite' and it should work.

    Also, if you're not already doing this, make sure it continues to re-position 'Sprite' until it finally finds a spot. Use a loop. Otherwise, it might re-position 'Sprite' once to avoid the overlap, but won't re-position it if it happens again.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • If necessary, because your sprites are spawning too fast, you'll need an array.

    Better ask R0J0hound to help ^^

    dl.dropboxusercontent.com/u/47035927/Samples/spawn_area.capx

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)