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

Get help using Construct 2

Post » Sun Dec 27, 2015 6:06 am

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?
B
6
Posts: 10
Reputation: 285

Post » Sun Dec 27, 2015 6:56 am

First create an animation with several objects
Image

and now you do this
Image
B
6
S
1
Posts: 34
Reputation: 474

Post » Sun Dec 27, 2015 7:16 am

These objects are spawning in different places, so I'm not certain that will work...
B
6
Posts: 10
Reputation: 285

Post » Sun Dec 27, 2015 7:37 am

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.
Brick by brick, stone by stone.
B
50
S
22
G
13
Posts: 273
Reputation: 10,413

Post » Sun Dec 27, 2015 8:51 am

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.
B
6
Posts: 10
Reputation: 285


Return to How do I....?

Who is online

Users browsing this forum: AllanR, Artpunk, QuantumMMX and 6 guests