Animate from and after key press.

linksunstriderlinksunstrider Member Posts: 22
edited November 2012 in Working with GS (Mac)
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.

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited November 2012

    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.
  • linksunstriderlinksunstrider Member Posts: 22
    Thank you very much, I'll try that right away, I'll let you know.
  • linksunstriderlinksunstrider Member Posts: 22
    Nope, :( not working, perhaps I didn't get it right. Any further explanation or help appreciated.

    The variable that checks the key is an integrer: attack_m
    http://img267.imageshack.us/img267/1861/screenshot20121125at634.png
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited November 2012

    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
  • linksunstriderlinksunstrider Member Posts: 22
    I'm using a keyboard key as the attack key, is not an actor in the scene to use a touch rule. :/
  • linksunstriderlinksunstrider Member Posts: 22
    edited November 2012
    A timer that forced the animation to play until done should work but I don't see why it doesn't, I'll try to start again with my main actor to clean up the file.. maybe is kinda bloated now.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited November 2012

    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.... ;-)
  • linksunstriderlinksunstrider Member Posts: 22
    Awesome!.. Think I got it working here!! Thanks for your help @gyroscope
  • linksunstriderlinksunstrider Member Posts: 22
    edited November 2012
    Everything is working fine with the tips you gave me, now I found a little problem, the "After" Timer I added to the Change Attribute (myboolean) to false, makes the actor to freeze if I spam the key a little.. Any idea why this might be happening?. Maybe I have too much stuff to check in my actor?..

    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.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    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.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    If you're watching through the viewer it can lag sometimes best to check it with an adhoc.
Sign In or Register to comment.