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

Get help using Construct 2

Post » Fri Apr 22, 2016 2:29 am

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?
B
9
S
3
G
1
Posts: 20
Reputation: 1,169

Post » Fri Apr 22, 2016 5:06 am

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.
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,283

Post » Fri Apr 22, 2016 9:50 am

Whats the animation speed ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Apr 22, 2016 1:42 pm

fernandokolbe wrote: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

Image


example.capx
Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896

Post » Fri Apr 22, 2016 8:01 pm

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.

Image
B
9
S
3
G
1
Posts: 20
Reputation: 1,169

Post » Fri Apr 22, 2016 8:23 pm

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



Coming soon on Steam!
B
16
S
9
G
3
Posts: 204
Reputation: 3,466

Post » Fri Apr 22, 2016 8:32 pm

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Apr 22, 2016 9:56 pm

(empty space)
Last edited by 99Instances2Go on Thu Apr 28, 2016 9:28 pm, edited 2 times in total.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Apr 28, 2016 8:52 pm

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.
ImageImageImageImage
B
62
S
19
G
51
Posts: 633
Reputation: 30,826

Post » Thu Apr 28, 2016 9:26 pm

You mean this ?

https://
drive.google.com/open?id=0B1SSuCVV8v74bGcxa0NjTTdtdkE
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: DharmaOne and 6 guests