...exit a loop prematurely

0 favourites
  • 3 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • Probably a quite simple thing to do, but I can't quite figure out how.

    My current event sheet basically looks like this.

    Global number "Scale" = 0.1


    Every 0.01 seconds -> Sprite -> Rotate 1 degree clockwise

    Every 0.01 seconds -> System -> Add 0.001 to "Scale"

                                 -> Set scale to "Scale"

    This, of course, keeps rotating and scaling the sprite indefinitely. Now what I'd like to do is stop scaling it the second it hits the 1.0 mark and stop rotating it the moment it's correctly aligned to the screen once again.

    Is there any quick way to do this? Preferably, I'd like to do all this in a while loop, though I have yet to figure out how while loops work inside Construct 2 (some things are just harder to do inside an FSM than they're in clear cut, C like code).

  • You could do it like this instead:

    Scale = 0.1

    every tick

    .. sprite.angle IS NOT 0

    ... sprite set angle: anglelerp(sprite.angle, 0, dt)

    .. sprite.Scale IS SMALLER THAN 1

    ... add dt to sprite.Scale

    ... sprite set scale to lerp(Scale, 1, dt)

    you could just take the sprite.scale IS NOT 1 condtions and add them to your example and it would work, but using lerp/dt will give you smoother effect on scale and rotation. :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could add a second variable called Final_Scale and set it to 1.00

    Add a second condition Scale <= Final_Scale (from the System, compare two values condition set), this way the condition will only execute until your Scale is equal to 1.


    Every 0.01 seconds && Scale <= Final_Scale -> Add 0.001 to "Scale" _. Set scale to "Scale"

    You want to stop the rotation when it's correctly aligned to the screen again... does that mean that you want it to rotate for 1 full revolution?

    If so, use a for loop

    For sprite.angle from 0 to 360 -> Sprite set Angle to: sprite.angle+1

    So this get the sprite angle (sprite.angle) and add 1 to it 360 times.

    Hopefully this helps.

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