How to stop spawning objects one on another in an imagepoint?

0 favourites
  • 5 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Every X seconds --> Spawn (Object) on (Object), imagepoint random(1, 12)

    ^

    That spawns objects one on another, sometimes. I tried destroying and respawning overlapping objects, but that does not work properly, as the same random objects just disappear. I found a topic like this one, but the answers confused me. Can someone help me please?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well random(1,12) is going to pick the same number sometimes, so you want it to spawn only once per imagepoint? My approach for this would always be to use an array with all relevant values pushed onto X then pick something from 0 to array.width. You then delete that X from the array so it can't be picked again.

    This could also work if something was destroyed on an imagepoint, you could add the number back into the array so it's selectable again if your game requires this.

    Also watch out with random(1,12) as that picks decimals so you probably want to use floor(random to get a whole number.

  • Well random(1,12) is going to pick the same number sometimes, so you want it to spawn only once per imagepoint? My approach for this would always be to use an array with all relevant values pushed onto X then pick something from 0 to array.width. You then delete that X from the array so it can't be picked again.

    This could also work if something was destroyed on an imagepoint, you could add the number back into the array so it's selectable again if your game requires this.

    Also watch out with random(1,12) as that picks decimals so you probably want to use floor(random to get a whole number.

    Ssssorrrryyy, I don't get how to do the thing you stated in the first paragraph of your reply, but thank you! It's just, could you please explain how it'd look like or give me a little .capx just so I can see how it is made? I am really a beginner, and clearly not a smart at that... Thank you!

  • I don't have a computer right now and won't have for a while, am just on my phone but didn't want it to seem like I was ignoring the post. Arrays do seem to scare everyone but they are fairly easy. All you are doing is pushing 12 numbers onto it and then picking a random number. But in an array you can remove the number you picked so it doesn't get picked again. I can't think of an easier way to do it but this way is super simple if you have looked at the array documentation.

  • I don't have a computer right now and won't have for a while, am just on my phone but didn't want it to seem like I was ignoring the post. Arrays do seem to scare everyone but they are fairly easy. All you are doing is pushing 12 numbers onto it and then picking a random number. But in an array you can remove the number you picked so it doesn't get picked again. I can't think of an easier way to do it but this way is super simple if you have looked at the array documentation.

    Alrighteth, thank you Plinkie!

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