Animation on key press - no behaviour - only events

Get help using Construct 2

Post » Thu Dec 31, 2015 1:09 am

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?
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 31, 2015 1:33 am

I would do it this way

Easy keyboard setup
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Dec 31, 2015 2:10 am

@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,
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 31, 2015 4:56 am

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.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 31, 2015 10:24 am

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
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Dec 31, 2015 3:45 pm

@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?
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 31, 2015 3:53 pm

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Dec 31, 2015 3:55 pm

@LittleStain - Hold on let me make a mockup capx and attach it.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 31, 2015 3:58 pm

@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.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 31, 2015 5:49 pm

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Next

Return to How do I....?

Who is online

Users browsing this forum: beohs, boybacteria, FabianB and 17 guests