Animate from and after key press.
Hello, I've been trying to make my character actor to have an animation behavior from the moment I press a key but I want the animation to be played until the end of it, as soon as I release de key, the animation stops.
I've tried a timer but it only flickers since I have a couple variables to use a still image.
The idea is basically this:
Character is:
grounded
not moving
facing X side
not pressing attack key
not pressing move keys
then change X side of "standing" image.
but when I try to do the following:
Character is:
facing X side
pressing attack key
then play X animation "For" 0.5 seconds, run to competition.
it plays fine as long as I keep the key pressed but as long as I release it, the animation gets interrupted OR blinks depending on the run to competition check.
Btw, the "standing" image rule is inside a timer that checks and keeps the images showing in the moment they're planned to.
Any ideas or workaround, am I using too much variables or complicating things too much?
Any help appreciated.
Linksunstrider.
I've tried a timer but it only flickers since I have a couple variables to use a still image.
The idea is basically this:
Character is:
grounded
not moving
facing X side
not pressing attack key
not pressing move keys
then change X side of "standing" image.
but when I try to do the following:
Character is:
facing X side
pressing attack key
then play X animation "For" 0.5 seconds, run to competition.
it plays fine as long as I keep the key pressed but as long as I release it, the animation gets interrupted OR blinks depending on the run to competition check.
Btw, the "standing" image rule is inside a timer that checks and keeps the images showing in the moment they're planned to.
Any ideas or workaround, am I using too much variables or complicating things too much?
Any help appreciated.
Linksunstrider.
Comments
Hi @linksunstrider (like your name, by the way!): try taking the animation behaviour out of the press rule, and trigger it with a boolean. So make a boolean called AttackAnim
When your attack key is pressed, and another rule, nested: when AttackAnim is false, change attribute AttackAnim to true.
Now a separate rule with your animation behaviour in:
When AttackAnim is true
Animate X animation
Timer: After 0.5 seconds
Change Attribute AttackAnim to false
Hope that sorts it for you.
The variable that checks the key is an integrer: attack_m
http://img267.imageshack.us/img267/1861/screenshot20121125at634.png
You're using a Constrain behaviour when you need a Change Behavior. Here it is again, a bit more clearly for you:
---In the attack key ---I'm assuming this is an actor button
Rule: When touch is pressed
Rule: (--- nested in above) When scene.attackM is false---- best to make the attribute a scene attribute in this case; and best not to use underscore (or, for info, hyphens, full stops, commas, etc., in attribute/actor names)
Change Attribute scene.attackM to true
-------
----I should clarify here: the following rule goes in your actor with the animation
Rule: When AttackAnim is true
Animate X animation
Timer: After 0.5 seconds
Change Attribute AttackAnim to false
If you trigger the animation via the boolean attribute, and you put as many frames in as is required for your animation time, (see description below) there's no need for a Timer for the Animate Behaviour.
----
Rule: When key M is down
Rule: (--- nested in above) When scene.attackM is false
Change Attribute scene.attackM to true
-------
----the following rule goes in your actor with the animation behaviour
Rule: When AttackAnim is true
Animate X animation
---- say you have 5 frames of animation, and you want this to run for half a second, then set the fps to the default 10fps---because it's triggered to stop by the boolean changing after half a second, it will stop after the 5 frames.
---if you're not happy with using Animate, another way to show your frames is by changing the image for .5 second, every .1 of a second. So whichever method you prefer----
Timer: After 0.5 seconds
Change Attribute AttackAnim to false
--- Nothing bloated about that.... ;-)
I was wondering the limits of GS and the right way to build a smooth platformer character.. I might be bloating my file to achieve it.
Thanks in advance.
Hi again linksunstrider, I'm pretty much certain you're not bloating your Rules...you have to go a long way to do that, I'm thinking...
Anyhow, providing the timer is in the actor that needs to be animated in the same rule as the animation behaviour, I can't see that pressing the key before the boolean is triggered would have any effect (in fact, I suggested the boolean switch to avoid that...
Rule: When AttackAnim is true
Animate X animation
Timer: After 0.5 seconds
Change Attribute AttackAnim to false
-----
But, if you want a different type of action being: every time you hit the key the attack sequence starts from the beginning, the rules would be even simpler.... let me know if that's what you're after and I'll amend the Rules for you.