How do I spawn to object?

Get help using Construct 2

Post » Sun Feb 07, 2016 2:10 pm

Hi to everyone

in my app i need to spawn an object, i have 12 differents fixed blocks and i want my object to spawn at one of those 12 different blocks
how can i achieve that?
i tried this formula but its not working: random(Meteor_generator.ImagePointX(0))
B
32
S
12
G
6
Posts: 1,625
Reputation: 8,575

Post » Sun Feb 07, 2016 2:31 pm

"Pick random instance" first, then spawn at it's ImagePoint.
ImageImageImage
B
71
S
20
G
202
Posts: 3,578
Reputation: 114,450

Post » Sun Feb 07, 2016 2:59 pm

You could always use "Pick instance with UID" along with Choose(0,1,2,3,4,5,6,7,8,9,10,11,12). I tried multiple ways to use random(0,13) but random doesn't seem to work well with Pick UID...
Of course the UID numbers I use assume your spawners are the first 12 sprites made in the project, otherwise you will need to use your UIDs.

but then if your spawner objects are all the same instance you could just use "Pick random instance".

Regardless, you will need to choose the spawn point first and then fire off the spawn.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
60
S
15
G
8
Posts: 619
Reputation: 8,970

Post » Sun Feb 07, 2016 4:14 pm

Random doesent work because it gives a number between 0 and 13 which could be 5,654365764 for example.
I guess it would work with round(random(13)) or floor(random(14).

But still "pick random instance" is the best option here.
B
7
S
2
Posts: 56
Reputation: 583

Post » Sun Feb 07, 2016 5:05 pm

i solved my problem by jus doing a random x position with the windows screen size :D thanks for your help
B
32
S
12
G
6
Posts: 1,625
Reputation: 8,575

Post » Sun Feb 07, 2016 5:53 pm

Random doesent work because it gives a number between 0 and 13 which could be 5,654365764 for example.
I guess it would work with round(random(13)) or floor(random(14).


That's right.. you would need to use floor(random(0,4)) for whole numbers.

Glad you worked it out!
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
60
S
15
G
8
Posts: 619
Reputation: 8,970

Post » Sat Feb 20, 2016 10:59 am

Hi. I will like to ask a question here so I don't have to create another post since is related with the title. I want to spawn/create an object to a random position of the player (in an area around the player). Something like Player.X(random(-200,200)) ; Player.Y(random(-200,200)) ; I can't figure out how to do this . Thanks ! :)
B
32
S
9
G
9
Posts: 198
Reputation: 6,712


Return to How do I....?

Who is online

Users browsing this forum: Ajbael, ome6a1717, the_Shit_hawk, Vodakman, zenox98 and 11 guests