Changing animation on key presses

This forum is currently in read-only mode.
From the Asset Store
Random Maze Generator with Door & Key System - tutorial capx
  • Hi,

    First off, I would like to thank developers for creating and maintaining Construct. I had found Construct one or two years ago, I have "quietly" read and learned from forum posts and Wiki tutorials. Now, I think it's time to ask for a help for something "more".

    I'm building a little 2D platform game from my crazy ideas; at this moment, I'm using Zero's sprites as, say, placeholders, so not intended to create a yet-another-fangame or such. All material not made by me will be replaced when the engine is done.

    Well, I'm having some troubles with changing animation on key presses. Let me explain better:

    The character is playing, say, a "running" animation, the player presses an "attack" key and a new animation is played. After the new animation is finished, the previous animation is played again.

    These are things I'm using:

    • obj_player is the hitbox.
    • obj_character is the animation.
    • obj_swordcollision is a detector.
    • "Running-Normal" is the 'running' state animation with no weapon.
    • "Running-Attack" is the 'attacking' state animation while running.
    • "action" is a variable: 0 = the character isn't using any weapon; 1 = the character is attacking.

    My detailed idea step-by-step

    1) obj_player is on ground, walking and "action" = 0

    2) obj_character: set animation to "Running-Normal"

    3) player1 presses "Attack" key and set "action" to 1

    4) obj_player: spawn obj_swordcollision (if it overlaps an enemy, such enemy is destroyed -- no effect yet and still visible for testings)

    5) obj_character: if on ground, walking and "action" = 1, set animation to "Running-Attack"

    6) After "Attacking" is done, set "action" value to 0 and destroy obj_swordcollision

    7) obj_character: if "action" = 0, set animation to "Running-Normal"

    What I've got trying so far..

    The "Attack" animation is played inconsistently. Sometimes, the EXE plays a certain frame each time on key press. In other moment, plays only a part of animation, and sometimes the animation is played 1.5x. Probably that's because the animation change depends on obj_swordcollision (see Event sheets screens below), but I don't have a better idea for now.


    Test2.exe (contains some weirdness, I hope you won't mind)


    Arrows: Movement

    Z: jump

    X: attack (sword, but does nothing yet)

    C: defense (shield, works like above)

    Event sheets

    Animation Event Sheet

    Controls Event Sheet

    I need some tips so I can fix it and go further with my work.


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • When setting animations, construct does not restart the animation. Basically it changes what animation is playing without changing the animation frame. That means if you're on frame five of your walk cycle and then switch over to your attack animation and your attack animation is only five frames long, it'll be like it barely played at all.

    What you want to do is put 'play animation' after an animation change when you want to play the animation from the beginning.

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