How do I spawn random sprites from a family on key press

Get help using Construct 2

Post » Mon Apr 07, 2014 9:19 pm

I've been looking all over and can't find anything specific to what I'm trying to do:

I've created a family of sprites, with 4 good sprites and 1 bad sprite
My main character is a graffiti artist who wants to spray paint his "tags" on a building
My character is able to approach the wall, and I want the player to tap the space bar at the point where he will spray paint his tag

The functionality I'm looking for is: 4 out of 5 times the player taps the space bar, one of his graffiti tags will be placed on the wall - but the 5th time a police officer will arrive to arrest him. It needs to be a random response so that the player never knows when the police officer will arrive.

I thought I was close with:
Event: keyboard, when space is down, system picks a random family member instance, with the family members numbered from 1-5
The action is to then set the position of the random sprite next to the graffiti artist - however, when I run this, all 5 sprites show up every time.
B
5
Posts: 5
Reputation: 235

Post » Mon Apr 07, 2014 9:57 pm

Just use system> create object> Family... it will randomly choose 1 object from that family..check the example capx
You do not have the required permissions to view the files attached to this post.
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Sat Apr 12, 2014 9:38 pm

Thanks so much, caiorosisca - I didn't get a chance to try it out until today, but it's working the way I needed. Now what I'm going to try to figure out is how to run an "if" statement off of it, so that if it generates object 1, something happens, but if it generates objects 2-5, then something else happens. I'm going to see if I can figure that out (I have PHP programming experience, but am trying to learn how to apply it within the Construct2 framework).
B
5
Posts: 5
Reputation: 235


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, R0J0hound and 14 guests