How do I go to one frame forward or one frame back?

0 favourites
  • 12 posts
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • I have a cannon that needs to rotate on a pivot. Each side is a different picture, so on pressing left or right, I need the animation to know to go forward or back one frame. Thanks!

  • You can use this string:

    self.animationframe+1

    and

    self.animationframe-1

  • Thank you! Works wonderfully. However, the cannon has 8 frames of rotation. Once it hits the last frame, it will not reset to frame 1. How do I do this so it can constantly cycle?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • you can just make a condition:

    on right pressed and animation frame is 8 set animation frame to 0

    on left pressed and animation frame is 0 set animation frame to 8

  • or just use modulo

  • you can just make a condition:

    on right pressed and animation frame is 8 set animation frame to 0

    on left pressed and animation frame is 0 set animation frame to 8

    I'm doing this now, although it skips frame 0 when going right, and right to 7. (Frames being 0-7)

    What would be the proper way to sequence this? Thank you for all your help so far, by the way.

  • You can of course use modulo as madspy said <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    Here is a capx of the first example.

    https://dl.dropboxusercontent.com/u/100 ... rames.capx

    Usually the on pressed trigger fires so quick that it effects the next frame as well so it skips a frame. By adding a wait 0.05 sec before every action fixes that. I did not place the events in the example as sub events so I could comment it nicely. But you can use sub events.

    But the most effective way would be to do as MadSpy suggested.

  • on right arrow pressed: sprite set animation frame to (self.animationframe+1)%self.animationframecount

    on left arrow pressed: sprite set animation frame to (self.animationframe+self.animationframecount-1)%self.animationframecount

  • You guys are wonderful! Thank you so much. Working perfectly now.

  • Nice, did you try MadSpys solution? It's pretty good to learn about modulo so it would be a good practice

  • I used the 2 codes he gave me and they worked! As far as Modulo, I am honestly not sure what that is, but I would love to learn.

  • % (modulo, remainder after division) https://www.scirra.com/manual/78/expressions

    eg

    0%4 = (0*4)+0 so returns 0

    1%4 = (0*4)+1 so returns 1

    2%4 = (0*4)+2 so returns 2

    3%4 = (0*4)+3 so returns 3

    4%4 = (1*4)+0 so returns 0

    5%4 = (1*4)+1 so returns 1 etc etc

    Note: animationframe can't be < 0 that's why you must add animationframecount before substract 1 to animationframe on 'left arrow pressed' condition

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