Use instance variable to set animation frame

Get help using Construct 2

Post » Mon Oct 19, 2015 9:02 am

I'm trying to do this :
When i click on a button, it's add 1 to a variable which define the frame of a sprite.
So every time i click, the sprite change. And when there is no more frame, it's go back to frame 0.
I've found in an old post that i must use instance variable, i tried but i don't really understand how to do this.
Thanks for your help.
B
4
Posts: 10
Reputation: 220

Post » Mon Oct 19, 2015 1:32 pm

try this:
Image
animation speed=0
B
66
S
24
G
7
Posts: 1,515
Reputation: 11,041

Post » Mon Oct 19, 2015 1:43 pm

That works, thanks a lot.
But i'm trying to understand the line. What is % meaning ?
B
4
Posts: 10
Reputation: 220

Post » Mon Oct 19, 2015 1:49 pm

B
66
S
24
G
7
Posts: 1,515
Reputation: 11,041

Post » Mon Oct 19, 2015 1:55 pm

Ok thanks.
i've added an other line :
Button2 / On clicked / Sprite Set animation frame to (Sprite.AnimationFrame-1)%Sprite.AnimationFrameCount
so i have a second button which decrease the value of animation frame
it works too but when the frame is 0 i don't know how to go back to frame 9 for example (if i have 9 frames)
so i will have a loop
B
4
Posts: 10
Reputation: 220

Post » Mon Oct 19, 2015 2:07 pm

almost...
i've added a sub-event so if i click on the second button and if the animation frame = 0 / Set animation frame to 9
it works but i don't see anymore the frame 0
i pass from 1 to 9 directly
B
4
Posts: 10
Reputation: 220

Post » Mon Oct 19, 2015 2:12 pm

Image
B
66
S
24
G
7
Posts: 1,515
Reputation: 11,041

Post » Mon Oct 19, 2015 2:47 pm

it works, thanks !
But i don't understand the difference between Sprite.AnimationFrameCount-1
and Sprite.AnimationFrame-1 ?
B
4
Posts: 10
Reputation: 220

Post » Mon Oct 19, 2015 3:13 pm

Sprite.AnimationFrameCount= the number of frames
Sprite.AnimationFrame= current frame

.let's say you have 10 frames..so Sprite.AnimationFrameCount=10..but last frame have index 9..
Image

so..if you want to set to last frame........Sprite.AnimationFrameCount-1=10-1=9
B
66
S
24
G
7
Posts: 1,515
Reputation: 11,041

Post » Tue Oct 20, 2015 6:17 am

Ok i understand.
Thanks a lot for your help.
B
4
Posts: 10
Reputation: 220


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 51 guests