How to find out where is the empty space on the game?


Please look at this image:

Suppose the circle in the middle of the game is supposed to appear randomly. How to find out what is the empty space on which the circle appears?
And it does not appear on another component of the game?
Is there any method?


Hello, There are many solutions to do this
For my old project I had the same issue with you,
My solution was

  1. Create an object, I named it “HiddenHitBox”
  2. Add its sprite but do not add anything on it (add an empty sprite)
  3. Make sure to check the ground and other object collision hitbox
  4. Spawn an object “HiddenHitBox” randomly on random x and random y or you can random between from x1 to x2 to y1 and y2 use RandomInRange() (I’m not sure, I’m not opening the game engine right now)
  5. Add an event to check if the “HiddenHitBox” is not collided with other objects
    (create a group that contains all object about your ground and maybe use it on the above event to reduce the block of repeating events)
  6. If the above is not collided then spawn the circle you want like this create an object circle at position HiddenHitBox X and HiddenHitBox Y

For the shorter version
-Do the trick by randomly place an invisible object
-If that object is not collide which means it’s valid for placing the real object then just place it and remove the invisible one
-If the invisible object is collided then delete it and spawn a new one and repeat

*It may not be the best way since the randomly spawn may never spawn on the empty space making your circle doesn’t spawn but I think it’s nearly impossible to happen.

I think this method will answer, but it’s too complicated!

I think there are other methods to do this task.
If I’m wrong please correct me.

Hi SaeedP, I haven’t tested this but it’s reasonably simple.

Put your ground/platform objects in a group.

  1. At beginning of scene - hide Circle, move Circle to random position

  2. Circle not in collision with GroundPlatform group - show Circle

  3. Circle in collision with GroundPlatform group - hide circle, move Circle to random position