How do I loop a movement function?

0 favourites
  • 3 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies. For use in game and custom works.
  • I have a sprite that I can rotate by holding down a button, that stops rotating when it reaches the angle 0. The sprite can be in any position and while I hold down the button, the sprite will rotate until it's the right way up again.

    Now I would like to turn this button hold action into a button press action. I want to press the same button once, and the sprite keeps rotating until it corrects itself, but I can't figure out how to use while/for loops with Construct.

    The second block of actions in the image is what I am trying to achieve(badly).

  • If you want something to happen over time, you do not want to use a loop. Loops resolve "instantly" in one frame.

    The entire event sheet is actually a loop that runs once per frame, so simply add a variable to keep track of the state of the sprite, for example "rotating". On button press, toggle "rotating" to true. While "rotating" is true, rotate the sprite.

    Remember to add an event that sets "rotating" to false when you reach the target angle. (Or nearly reach, watch out for rounding problems)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you, I'll give that a go.

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