How do I pick a specific object in a family

0 favourites
  • 5 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • I've got a Family called fml_weapons with 4 sprites

    the Family has a variable called 'name' and i set each sprite in the family with a unique name ('missile', 'red laser', 'green laser', 'blue laser')

    what i would like to do is set the 'Z' key to fire the red laser, so i set up the code this way:

    System --> Pick fml_weapons where fml_weapons.name="red laser"-->Spawn fml_weapons sprite

    however, the result is a random sprite from the fml_weapons Family gets spawned

    I know i could just spawn the red laser sprite on 'Z' key pressed, but this key won't always lead to the same weapon, eventually, the player will setup his weapons from an array

    thanks

  • When you spawn a family, you can't control which family member will be created, it's random.

    So you need to create the object explicitly: "if currentweapon=laser, then create laser, else if currentweapon is missile, then create missile" etc.

    Alternatively, you can ditch the family, combine all these sprites into one as different animations. Then on "Z" pressed, you spawn this one bullet sprite and only need to change its animation.

  • thanks for the reply, i appreciate it;

    eventually there may will be dozens of types of weapons to choose from, that's why i was thinking of a family construct to make the picking easier

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can pick sprites by animation name. If you want to continue using the family, you'll have to add a bunch of events for creating individual weapons, there is no workaround for this in Construct 2.

  • as dop2000 said, you can't automatically pick instance of the family but you can give the family a couple of variables, one for the weapon it uses and a second one for the ID of the instance.

    for example if you already have the sprite that carries the weapon place in screen and you don't create another one you can say

    on start of layout for each sprite.withweapon ascending

    sprite.withweapon.setvariable gun to "abs ( round ( random ( 0 , 4 ) ) )"

    blank subevent under start layout

    action wait 0

    subevent

    sprite.withweapon compare self variable gun if equal to 1 lets say

    action

    create gun on sprite.withweapon

    gun set animation to redlaser.

    now when it shoots, you compare which gun the sprite.withweapon has and spawn the bullet/laser based on that.

    so

    condition

    if sprite.withweapon is shooting

    and Pick sprite.withweapon where gun value is 1

    action gun create laser.object at gun image point 0,0

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