set animation frame based on instance variable

Get help using Construct 2

Post » Sat Aug 18, 2012 6:36 pm

I have several sprites on stage.
They have an instance variable 'damage' set to 0
They have several animation frames and Speed = 0 and Loop = No
I loop thru the sprites using 'For each'.
I set the damage variable to 'Add 1 to damage'

I would like to set the animation frame to match the damage variable.
So each time the damage variable increases, move the sprite animation to the next frame.

[when it reaches the end of the animation frames, I'll destroy that sprite]
B
7
S
1
Posts: 11
Reputation: 929

Post » Sat Aug 18, 2012 6:42 pm

Sprite: set animation frames to "damage"

there's an action "Set frame" for sprite, insert there your instance variable name there.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sat Aug 18, 2012 6:55 pm

@shinkan

Yes, I tried that and I get this message
"Unknown expression 'damage'. This is not a system expression or variable name in this scope
B
7
S
1
Posts: 11
Reputation: 929

Post » Sat Aug 18, 2012 7:10 pm

instead of "damage" select your sprite from the window on the right (Objects with expression) and there's a section called "Instance Variables" which shows you all variables for current sprite.

If your object is called "ship" and your instance variable is called "damage" it will look like this ship.damage

##.$$

where # is your instance name
$$ is your variable name for that instance


Edit: remember that Animation frames are number based, so your instance variable should be numbers too.shinkan2012-08-18 19:11:17
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sat Aug 18, 2012 7:34 pm

Got it - and thanks for the details
B
7
S
1
Posts: 11
Reputation: 929

Post » Thu Dec 13, 2012 8:13 pm

Thanks Shinkan, older post but answered my question too
B
10
S
2
G
2
Posts: 45
Reputation: 2,039

Post » Mon Oct 19, 2015 7:57 am

Hi
I have the same question but i begin with Construct 2 and i didn't understand how to do that.
Can you help me ?
My idea was a button with action onclicked that for each click add 1 to a variable and the variable define the frame of the animation of a sprite.
I click and my sprite goes on frame 2, i click again the sprite goes on frame 3 etc... and if i've got only 9 frames, if i click 10 times the animation goes back to frame 0.
Thanks for your help.
B
4
Posts: 10
Reputation: 220

Post » Mon Oct 19, 2015 8:05 am

@Grenouye

Grenouye wrote:Hi
I have the same question but i begin with Construct 2 and i didn't understand how to do that.
Can you help me ?
My idea was a button with action onclicked that for each click add 1 to a variable and the variable define the frame of the animation of a sprite.
I click and my sprite goes on frame 2, i click again the sprite goes on frame 3 etc... and if i've got only 9 frames, if i click 10 times the animation goes back to frame 0.
Thanks for your help.


This is a very old - 3 years - thread you're bumping.

You would be better creating a new topic just for your question.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,849
Reputation: 48,299

Post » Mon Oct 19, 2015 8:52 am

Ok thanks, i will do that.
B
4
Posts: 10
Reputation: 220


Return to How do I....?

Who is online

Users browsing this forum: Justin1967, vodka and 21 guests