How do I get a random sprite position

Get help using Construct 2

Post » Tue Dec 02, 2014 9:34 am

hi,
i have 5 fixed sprites (all the same sprites), now i want to get the position of one random sprite of them.

thanks
meta
B
5
Posts: 42
Reputation: 313

Post » Tue Dec 02, 2014 10:39 am

Hello metameta, first let me welcome you to the community!

By coincidence i came across your post, though i find it hard to understand what precisely is your problem.
For what i understand from your explanation is this:

You have 1 sprite on your layout, you copied it 4 times creating 5 identical sprites on your layout.
You want them to be placed on random locations on the layout?

If this is not the case then please try to give a more detailed explanation of your problem, and i will try my best to help you out!

Greetings,
dwngrt
B
10
S
1
Posts: 2
Reputation: 599

Post » Wed Dec 03, 2014 6:54 am

hi dwngrt,
first part is correct - i've one sprite which i copied it 4 times = 5 same sprites. these sprites are on a fixed possition on the map

now i want to get the location of ONE of them (random) and e.g. destroy this sprite --> 4 sprites left....

thanks!!!!
-meta
B
5
Posts: 42
Reputation: 313

Post » Wed Dec 03, 2014 7:28 am

You don't need the location to destroy it
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Dec 03, 2014 8:39 am

You should be able to pick a random sprite. I'm not sure whether there was a pick random but if not:

- Generate a random number using the random function. Its max value should be the number of sprites you have in the map -1 (because of 0-index). Theres a variable for this.
- Use the random number to get a sprite by its IID (index iD) and get its location.
- Destroy it.
B
18
S
6
G
3
Posts: 30
Reputation: 4,208

Post » Wed Dec 03, 2014 10:33 am

Hey metameta,

Hopefully you already figured a way to accomplish your goal.
If not: then this demo might help you a bit.

demo.capx



Dwngrt
You do not have the required permissions to view the files attached to this post.
B
10
S
1
Posts: 2
Reputation: 599

Post » Wed Dec 03, 2014 1:10 pm

perfect! thx a lot!
B
5
Posts: 42
Reputation: 313


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 11 guests