Families, checking for all sprites in family if none is in animation frame 1, or at least one is

0 favourites
  • 8 posts
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • Hello,

    i have three boxes (sprites) which upon touch change color (from white to red).

    I have a fourth box, which is supposed to change color when at least one of the three boxes is red, otherwise it should be white.

    I am using a family to capture all three boxes (because in the future there could be several more).

    How to i build an event condition for:

    at least one box is colored (i.e. in Animation frame 1)

    none of the boxes in the family are colored (in Animation frame 1).

    I tried to use the system loop, and pick all with a subevent condition, but neither worked. I am doing something wrong here.

    any thoughts would be much apprecited,

    Dan

  • So your problem is with the (fourth box) that it should change the color when one or more boxes from the family change color?

    or

    When One of the Family boxes changes color none of the other two boxes on the family should be colored?

    it's a bit confusing what exactly you trying to archive

  • Thanks.

    Sorry for the confusion.

    The fourth box should be red, if at least one of the three boxes is red, otherwise it should be white.

    Each of the three boxes toggles through red and white -- each time its touched.

    Dan

  • Also, i am changing the color of the boxes by setting (toggling via modulu %) the AnimationFrame value to 0 or 1 -- the zero frame is white, the one frame is red.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • what i need to be able to do, for example, is loop over each sprite instance of an object type in a family, and add up the current animation frame number.

    In pesudo code this looks like this:

    set global variable v = 0

    for each instance inst of object type in family boxes

    add to v inst.animationFrame

    This code should run everything any of the boxes is touched / tougled

    this would yield a number that indicates if all animation frames are zero -- i.e. white, or at least one red, i.e. the sum is greater than zero.

    But, i don't see a way to do this with family

    the only way i see right now is to hard code the sum using the actual sprite names

  • Thanks.

    Sorry for the confusion.

    No problem mate

    is it something like this?

    https://www.dropbox.com/s/xevtnf2s9p9b4ah/ColorChange.capx?dl=0

    For the explanation you gave it looks like you have 4 separate objects so I follow your design but I don't think you need separate objects or families in this situation, let me know if something is wrong

  • what i need to be able to do, for example, is loop over each sprite instance of an object type in a family, and add up the current animation frame number.

    In pesudo code this looks like this:

    set global variable v = 0

    for each instance inst of object type in family boxes

    add to v inst.animationFrame

    This code should run everything any of the boxes is touched / tougled

    this would yield a number that indicates if all animation frames are zero -- i.e. white, or at least one red, i.e. the sum is greater than zero.

    But, i don't see a way to do this with family

    the only way i see right now is to hard code the sum using the actual sprite names

    Hoo I see, You don't need a loop for that, you need just a simple comparison of the Frame it will loop automatically through all the instances matching the condition if none is found the Else, in this case, means all the family Frames are = 0

    see event 5 where I call the Function

  • wow, great ...

    i will study your code carefully,

    thanks!

    dan

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