GameSalad

Animating "change image"

I have an actor that animates when hitting jump key. One way I found to change direction of image of actor is to change image when left key is down. Now i cant figure out how to animate the left facing image. I have the png files ready but dont know how to create the rules. Should i use change attribute?

Comments

  • SocksSocks London, UK.Posts: 12,698Member, PRO

    Use the Animate behaviour.

  • dogwardogwar Posts: 3Member

    Thank you but i have done that for the right facing image. I cant figure out how to animate left facing image after pressing left key and actor changes image to left facing. The actor faces left until i hit the jump key again and now right facing animation pops back up.

  • pHghostpHghost London, UKPosts: 1,904Member

    You can flip the actor orientation. Self > Graphics > Flip Horizontally.

    That will flip the whole actor, so you only need images facing in one direction.

  • rainwaterstudiosrainwaterstudios Posts: 70Member, PRO

    I figured out a way to animate actors using Tables, and it seems to work seamlessly (so far). If you'd like an example I can send you the project file

  • pHghostpHghost London, UKPosts: 1,904Member

    @rainwaterstudios said:
    I figured out a way to animate actors using Tables

    How taxing is that on the runtime? I'd be quite interested to have a look at that.

  • rainwaterstudiosrainwaterstudios Posts: 70Member, PRO

    Here's an example I whipped up.
    Scene 1 shows my method for animation from Tables, Scene 2 is the same animation but using the 'Animate' behavior, and Scene 3 shows them side by side.

    Let me know if this helps or if you have any questions about how to set this up within your project!

    Cheers,
    Connor

  • pHghostpHghost London, UKPosts: 1,904Member

    Very nice! And really easy to loop it as well, just adding one Change Attribute.

    Comparing the memory usage and performance, looks good as well. Of course, seeing a project with multiple animated actors would give a better test opportunity, will play around with it at some point.

    Great thing is that you can have all of one actor's animations in one single table and dynamically switch between them!

  • SocksSocks London, UK.Posts: 12,698Member, PRO
    edited February 27

    @pHghost said:
    Very nice! And really easy to loop it as well, just adding one Change Attribute.

    You can do the whole thing somewhat easier (no rules, no attributes, no tables - etc) and with less processor overhead with a simple constrain:

    Constrain image to floor(increment*frame rate)%loop

    And . . . as we are not using rules that check conditions that then trigger timers (and within those timers, behaviours) we are not limited by the Timer behaviour's 1/30th second (30fps) limit, you can run animations up to 60fps, and as well as being able to run animations at much higher speeds you can easily run them backwards, or back and forth in a loop, or speed them up or slow them down as they play . . . . (etc etc) . . . all the while massively simplifying the process (a single Constrain behaviour) and placing less strain in the processor.

  • pHghostpHghost London, UKPosts: 1,904Member

    @Socks said:
    Constrain image to floor(increment*frame rate)%loop

    There must be something I'm not understanding, because I cannot seem to get it to work.

  • SocksSocks London, UK.Posts: 12,698Member, PRO

    @pHghost said:

    @Socks said:
    Constrain image to floor(increment*frame rate)%loop

    There must be something I'm not understanding, because I cannot seem to get it to work.

    Can you post a shot of your constrain behaviour . . .

  • pHghostpHghost London, UKPosts: 1,904Member

    I'm not at my computer (probably until the evening), but here's how I have it set up:

    Three game attributes:

    game.increment
    game.fps
    game.loop_length

    They are set to 1, 24 and 48 respectively. That's if I understand correctly that by increment you mean how many frames forward to jump per step.

    Then in the behaviour I constrained it as you wrote:

    constrain self.image to floor(game.increment*game.fps)%game.loop_length

    If I remember correctly.

    I tried playing around with the formula and always ended up with one of two results:

    1. The animation wasn't happening at all.
    2. The animation was happening in the correct range of images, but at the framerate of the app 60fps.
  • pHghostpHghost London, UKPosts: 1,904Member

    Here's the screenshots @Socks


  • SocksSocks London, UK.Posts: 12,698Member, PRO
    edited March 1

    @pHghost said:
    That's if I understand correctly that by increment you mean how many frames forward to jump per step.

    Sorry, I explained it really really badly ! :# :) (really badly!!)
    (what I mean by 'increment' was the number that was driving the animation)

    Let me start again . . . with an actual example, if you had a 21 frame image sequence (21 images) starting at '0' and ending with '20' (so the file names are simply the frame numbers), and you wanted it to loop at 30fps then you would constrain self.image to . . .

    floor(self.time*30)%21

    If you wanted a 16 frame sequence to loop at 60fps, then . . .

    floor(self.time*60)%16

    . . . and so on . .

    And if your image sequence has a name (so 'jump0', 'jump1', 'jump2', 'jump3', 'jump4' rather than just '0', '1', '2', '3', '4' . . ) then you would constrain self.image to . . .

    "jump"..floor(self.time*60)%15

    And if your image sequence starts at 1 rather than 0 then just add an offset to the calculation like this . . .

    "jump"..(floor(self.time*60)%15)+1

    Or if you want it to loop between frame 4 and frame 10 . .

    "jump"..(floor(self.time*60)%6)+4

    . . . and so on . .


    But this approach becomes a really flexible animation tool when you use a separate rotating actor as the animation controller - rather than something like game.time.

    So, we have our animating actor, and we have a second controller actor, let's call it X.

    Set up your animating actor as above . . . but with the rotation of X as the number that drives the animation . . .

    floor(X.rotation)%21

    Now you throw a rotation behaviour onto the controller actor.

    If it rotates CCW at 30°/sec ('speed' 30) then your animation will loop at 30fps
    If it rotates CW at 60°/sec your animation will loop backwards at 60fps

    . . etc etc

    If you use a Rotate to Angle behaviour, and set it to rotate to (angle) 21° (relative to actor) on mouse down, then the animation will play through every time the mouse button is pressed (or screen touched) at the speed specified in 'speed'.

    Or you could use a constrain the controller actor's rotation to a sine wave and have your animation smoothly play backwards and forwards backwards and forwards . . . in a loop

    And if course it's easy to do things like pause your animation by simply stopping the controller actor rotating.

    The combination of a rotating controller actor and the simple constrain behaviour on the animating behaviour [ floor(X.rotation)%21 ] gives you a simple animation tools that allows you to do just about anything you might want very simply.

    Want your animation to slow to a halt over time, then add some angular drag to your controller actor so it slows to a stop, want your animation to play random frames, then set your controller actor to change rotation to a random every X seconds . . . etc etc

  • pHghostpHghost London, UKPosts: 1,904Member

    @Socks said:
    But this approach becomes a really flexible animation tool when you use a separate rotating actor as the animation controller - rather than something like game.time.

    Aha! Yes, this is really smart. Nice approach! I'll definitely have a play with that.

  • SocksSocks London, UK.Posts: 12,698Member, PRO

    @pHghost said:

    @Socks said:
    But this approach becomes a really flexible animation tool when you use a separate rotating actor as the animation controller - rather than something like game.time.

    Aha! Yes, this is really smart. Nice approach! I'll definitely have a play with that.

    Sorry, long time to reply, I missed your post !!

    Yes, it wipes the floor with the Animation behaviour in every way possible - and is really really simple to set up and control. For a lot of things the Animation behaviour is just fine (I use it all the time), but when you need to do anything like pause an animation or play it backwards or have it slow down or speed up or play faster than the Animation behaviour's 30fps (etc etc) then this system is not only really straightforward but endlessly flexible.

Sign In or Register to comment.