How do I set a variable to trigger a frame from animation?

0 favourites
  • 10 posts
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • So, I have my player with 5 HP (health).

    And I have an animation with 5 frames. Each representing the number of hearts of the health. Each damage, player loses 1 HP (and 1 heart from animation).

    What I want to do, and I'm not being able to, is something like this:

    If HP = 5, set animation frame to 1

    If HP = 4, set animation frame to 2

    And so on.

    What is happening is that the animation is not changing upon receiving damage, and is playing from the beginning as well (not being triggered by the value change).

    Any idea on how to do that?

  • You should post a screenshot of code. There might something else going on there. Try creating each frame as a separate animation and call them by animation name.

  • Whats the animation speed ?

  • So, I have my player with 5 HP (health).

    And I have an animation with 5 frames. Each representing the number of hearts of the health. Each damage, player loses 1 HP (and 1 heart from animation).

    What I want to do, and I'm not being able to, is something like this:

    If HP = 5, set animation frame to 1

    If HP = 4, set animation frame to 2

    why not?

    If HP = 5, set animation frame to 5

    If HP = 4, set animation frame to 4

    or in one event:

    ................set animation frame to HP

    example.capx

  • Hello guys, all answers helped me a lot. None actually worked for how my project is setup, but it gave me ideas of how to fix it myself.

    I managed to make it work, so I'm posting a image if someone looks for a solution to this problem in the future and wants another way of trying it.

    I guess I just added to many values that were conflicting because meant the same thing or different things, as I explain in the image.

    And the object its the same, its frames. I tried the different animations solution but didn't work, I was probably doing something wrong. I'm new to Construct 2 and new to coding (even tho this is not coding, the logic behind is), so I need to get more used and this forum is helping me a lot.

  • Could you sum up that stuff in one line that just sets the health sprite animation frame to HP - 1?

  • Why not make frame and HP match ? You can rearange frames in the animation editor. Make a fake frame for the zero. Only ONE animation with its speed on ZERO.

    Then 'on each tick' set frame nr to HP

  • (empty space)

  • Alright so I think this is actually related to a new bug. I have a setup where literally on clicking an object, I set the animation frame. The only thing that works is setting the animation frame to a previous frame. This is why I think it is unintended behavior and not just a function/limitation.

    But yeah, if the animation frame of my object = 1, I cannot set it to 2. But I can set it back to 0.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You mean this ?

    https://

    drive.google.com/open?id=0B1SSuCVV8v74bGcxa0NjTTdtdkE

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