0 Favourites

set animation frame based on instance variable

  • 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]

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Sprite: set animation frames to "damage"

    there's an action "Set frame" for sprite, insert there your instance variable name there.

  • 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

  • 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.

  • Got it - and thanks for the details

  • Thanks Shinkan, older post but answered my question too

  • 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.

  • Grenouye

    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.

  • Ok thanks, i will do that.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
1,941 263,201
FlyingRam's avatar
FlyingRam
Unread hot topic
0 Favourites
[Plugin] instance bank2
85 18,367
rexrainbow's avatar
rexrainbow
Unread hot topic
88 9,239
goldentreee's avatar
goldentreee