Animation on key press - no behaviour - only events

0 favourites
From the Asset Store
Random Maze Generator with Door & Key System - tutorial capx
  • I did not think I would post this as I thought I had this one figure out. Well it turns out I dont.

    Ive set up my manual 8 direction movement using events instead of the built in behaviour.

    Now my code it as follows:

    On Left press --> play "Left" animation

    On Right press --> play "Right" animation

    On Up press --> play "Up" animation

    On Down press --> play "Down" animation

    On any key released:

    ----> Invert Left is down

    ----> Invert Right is down

    ----> Invert Up is down

    ----> Invert Down is down

    ----------------------------------------->play animation "idle"

    Now all is good apart from playing animations while the player is moving diagonally, ie. when up-left, up-right, down-left and down-right are pressed. Now when I press any of these the player moves alright but the animation is set as either top or down animation but as a frozen first frame.

    Any idea how I can implement the diagonals in the code? Ive tried else, and loop nesting but couldnt seem to work this into my events.

    Thanks for your time, this seemed such an easy task but I am stuck in the moment.

    Is there any other way than using angles?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would do it this way

    Easy keyboard setup

  • LittleStain

    Many thanks! The first 2 groups is something I should have thought about. Its just that Ive got loads of variables so far and implementing additional variables starts to feel like a chore.

    The part with the dictionary is something I havent yet worked my way through. Seems like the perfect opportunity,

  • Doh! Now I cant seem to implement that every random(a,b) seconds while the stationary button - meaning no button is pressed, another idle animation is played - sort of a waiting easter egg if you know what I mean. Seems you cant have it all, eh?

    If I add this event below the keypress and what not, I have problems with the animation fluidity, they dont seem to stop with regards to letting go a key as they seem overwritten by the random animation event.

    I even tried to call a function when no button is pressed, and that function had: every randoms seconds play idle_02. That does not stop the animations proprely once I let go of a key, but plays them untill the end.

  • I don't see why this would give any issues..

    keyboardinput = 5

    every random(a,b) seconds

    trigger once

    • play animation idle 2

    on animation idle2 ended

    • play animation idle
  • LittleStain

    Well its not working properly. As I wrote before this condition is forcing the other movement animations to play out until the end, and not stopping them and not going into playing Idle once a key is not pressed, once keyboard input = 5.

    Not only that, it is freezing the last frame of the movement animations depending on which direction was pressed last, and not returning to Idle animation, but waiting for idle 02 to play out in the random seconds given. Only then is it going to idle 01.

    What I want to achieve is to have idle play out when no keys are pressed - and to do that instantly, on letting a key go. Idle is simply 1 frame of an idle animation. Then once Idle is played, I want in time random(a,b) for idle02 to play.

    Any other workarounds?

  • Without knowing how your events are set up regarding animation I can't really give any advice..

    This should work perfectly if everything is set up correctly..

    In my example you should play the animations based on the instance variable keyboardinput, or (maybe easier) the name derived from the dictionary..

  • LittleStain - Hold on let me make a mockup capx and attach it.

  • LittleStain

    Wait - but now - look how the events are set up:

    keyboardinput = 5

    every random(a,b) seconds

    trigger once

    • play animation idle 2

    on animation idle2 ended

    • play animation idle

    So basically once a key is not pressed the system waits random(a,b) seconds before playing the idle02 animation. So it is waiting on the last frame of the animation of the direction that was pressed, and not going straight to idle animation when keys are not pressed/or when keys are released. Only then is it going to idle 02 and then to idle. Am I not understanding this correctly?

    But I want it to go to idle instantly and then wait for random(a,b) to play idle02.

  • Ofcourse you should set animation idle playing if keyboardinput is 5..

    You could add an is animation idle2 not playing condition to that event..

    I guess then you wouldn't even need the on animation idle2 ended event..

  • The thing is that the idle animation is only 1 frame long, and I want it to last for the minimum amount of seconds that I am inputing in the random(A,b).

    https://www.sendspace.com/file/4uxvcm

    Here is the file as you can see at this moment the animation Idle02 plays on 1 frame and then is switched back to Idle.

    When I add on "finished animation" for Idle02 play idle, that causes the moving animation not to be stopped when no buttons are pressed and inputkeyboard=5 kicks in, but keeps on playing the moving animation until the moving animation has ended.

  • You do know every x seconds is counted from the start of the game and not from the moment the condition becomes true?

    it would probably be better to use wait or timer behaviour to accomplish this..

  • You do know every x seconds is counted from the start of the game and not from the moment the condition becomes true?

    it would probably be better to use wait or timer behaviour to accomplish this..

    LittleStain

    Of course you are right, but in this situation it doesnt matter as both arent working as you will see in the attached capx where I have changed to wait random(a,b):

    https://www.sendspace.com/file/bcmrqg

  • Well ofcourse this doesn't work..

    every tick keyboardinput is 5, the animation is set to idle..

    if you add the condition

    sprite is not playing animation "idle02"

    it swiches animations

    adding the event

    on animation "idle02" finished

    set animation to idle

    will make the switch complete

  • LittleStain

    Thanks for your time.

    Hmm, but the wait random(a,b) to play other animation is set within the keyboard input 5, does it not go down the condition branch every a,b seconds then?

    As the idle animation has 1 frame, when I add the "set animation to idle" it will automatically play idle02 once again.

    Anyway I will try what you suggested first along with the random(a,b) then Ill get back to you.

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