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

0 favourites
  • 3 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • 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.

  • Just use system> create object> Family... it will randomly choose 1 object from that family..check the example capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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).

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