How do I spawn one of several objects, but only one?

0 favourites
  • 5 posts
From the Asset Store
Several elements of the game interface hidden objects
  • I have seven objects I want to spawn randomly, but I only want one object at a time to be on the screen. Anyone know how to do that?

  • First create an animation with several objects

    and now you do this

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • These objects are spawning in different places, so I'm not certain that will work...

  • You need to provide a little bit of information.

    For how long should the object be on screen? What are is the condition under which it will be destroyed? Timer, enemy collision or on button press?

    Is the spawning point of the objects set to be anywhere on the whole screen?

    Basically you need to set up a variable that checks if the object is on screen.

    I usually go with numeric variable and set 0=not true 1= true, as in binary code on/off.

    Object_spawned_on_screen = 0

    IF Object_spawned_on_screen = 0

    Create object at position (x=random(0,yourscenewidth),y=random(0,yoursceneheight)) ----> example: if scene is 640x480 enter accordingly

    Set Object_spawned_on_screen=1

    Wait 4 seconds

    Destroy Object

    Set Object_spawned_on_screen=0

    Now there can be a problem where your object spawns half cut at the edge of the screen. In this situation we need to add a margin to the spawning area above, basically depending on the margin and the size of the sprite we can either add a pixel amount, half of the object sprite, or the whole width and height of the object.

    So for example:

    (x=random(100,yourscenewidth-100),y=random(100,yoursceneheight-100))

    This will give you a 100 pixel buffer around the scene, where the object will not spawn.

  • okay, so the area I am trying to spawn in has an x range of 71 to 744, so each object (when it spawns), will need to spawn inside that area, and not the rest of the viewable screen (which has a layout size of 854, 480. So if I understand you correctly, it should look like:

    x=random(71,744) since that is the area I want it to spawn within, or x=random(71, 854 - 110) ?

    Is that correct?

    The object will be onscreen until another icon is clicked, at which point it will destroy and spawn another random object, up to 10 times. I have everything else down, except for the spawning randomly and the random placement of the spawning. The items will be stationary once spawned.

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