...exit a loop prematurely

Get help using Construct 2

Post » Mon May 27, 2013 2:16 pm

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).
B
6
S
2
Posts: 206
Reputation: 1,685

Post » Mon May 27, 2013 3:20 pm

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. :)
B
24
S
9
G
7
Posts: 756
Reputation: 7,292

Post » Mon May 27, 2013 3:27 pm

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.
So:
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.
B
28
S
10
G
10
Posts: 96
Reputation: 6,582


Return to How do I....?

Who is online

Users browsing this forum: AkbarAsgharMG, Baidu [Spider], bpotts1980, cjbruce and 10 guests