How do I set particle object from a family?

1 favourites
  • 10 posts
From the Asset Store
Particles support animations, collisions, effects and etc.
  • Hi! I have different particle sprites in different colors and tried to use a family with instance var to select a specific one in a function without the need to write one line for each color like this:

    ----+ Text: ID = "Black"

    -----> Exhaust: Set particle object to Exhaust_Black

    ----+ Text: ID = "Red"

    -----> Exhaust: Set particle object to Exhaust_Red

    I tried to select the Family by Instance Var (with compare instance var, pick by evaluate etc.) but when I use Set object to Family its always spawning random family members as particles not jus the color specified.

    * On function 'SetExhaust'

    * Parameter 'ExhaustID' (String)

    ----+ Exhausts: ID = ExhaustID

    -----> Exhaust: Set particle object to Exhausts

    Is it possible to use a single color from the family somehow?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • When you create a family instance, it always selects a random member of the family. I guess it's also true for particles object.

    The solution is not to use families. Combine all colors into the same sprite, as different animations or frames. You can set required animation/frame in "On created" event. Or make just one white sprite and re-color it with "Set color" action.

  • I would probably do what Dop suggested, but you can also create the object by its name to get the color you want, then use the family name to simplify code in other areas. (The UID will be the same whether you pick by the object name or the family name.)

    another advantage of Dop's suggestion is that you could then add the object to a container so that the correct instance is picked with the parent object.

    since particles can't have animations or frames, you will either have to use the "Set Color" option or a family...

  • Thanks. Picking family member by ID worked fine with arrays in another project but it seems it does not work with particles since family means: pick random family member.

    Using one sprite may work for now but if I add too many items it's getting very big and memory intensive. Cause all anims and images are loaded even if only 1 is needed. But I'll try. 👍

  • if you use create object to create a new family instance, you will get a random member of the family (unless you give it the object name you want - not the family name).

    but if you save the UID of an object, you can pick by UID using the family name and will get the object you want - not a random instance.

  • you can also create the object by its name

    AllanR I believe op was asking about the sprite which is spawned by Particles particles, instead of the own particles image. See "Object" property on the left panel - you can only select an existing object there.

    I may have misunderstood the question though. If it was about multiple Particles objects combined in a family, then I agree, it's easier to create them by name.

  • I just tried to pick by UID and then set the family but it does not seem to work for particles. If you assign a family it seems to always use a random instance.

    + System: Pick Exhausts(family) by evaluating Exhausts.UID=183

    -> Exhaust: Set particle object to Exhausts(family)

    Don't know if this is just the way it works or if I did it wrong. Or maybe it can be changed/fixed to allow filtering by ID/Variable? Ashley

    It worked fine with 4 arrays in a family where I just used compare instance var to assign actions to a specific array.

  • I tried to use sprite animations but when I switch the animation it shows the particles in the new color for a moment but then goes back to the initial black color.

    * On function 'SetExhaust'

    * Parameter 'ExhaustID' (String)

    -> Exhaust_Particles: Set animation to ExhaustID (play from beginning)

    I tried to set the object again and then changing anim but its the same as just changing the animation.

    Any idea why it goes back to black after setting the animation?

    /update:

    I made a small example project:

    1drv.ms/u/s!AvV_VKT3P7wZiegZm4mbzXuPga5oow

    Is this a bug? Ashley

  • Bl4ckSh33p I might be wrong about this, but I think it's because when you click the button the animation change only affects the animations on instances of the Sprite object that currently exist - as new particles are generated the initial animation settings are used.

    To permanently change the animation you would have to do it in an "On created" condition for the spawned Sprite object.

    UPDATE: Yep, just modified your example - if you add a global variable string "id", on pressing a button set "id" to the button ID, and then Sprite|On created set animation to "id", it works as intended.

  • Thank you very much mekonbekon!

    + Exhaust_Particles: On created

    -> Exhaust_Particles: Set animation to TempExhaust (play from beginning)

    Works fine. :)

    But it would be nice if you could select specific family members by ID/variable for particle objects, too.

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