In the blocks editor, we create these 3 variables:
Then we create this procedure:
And this Clock.Timer event:
What this group of blocks does?
It’s a Timer event that once enabled will be triggered every 50 milliseconds until it is disabled:
First, it makes the device vibrate.
Then it uses the method TextUtils.Rotate to rotate the specified component in the angle provided. But here’s the trick: Every time it gets here the angle is NEGATED, so if the angle is 3 in the first event, next will be -3, then the next will be 3, -3, 3, -3 etc, etc. That way, the components gets rotated rapidly between 3 degrees and -3 degrees, simulating a shaking movement.
How do we negate a number? By multiplying it by -1 (i.e. 8x-1=-8, -4x-1=4)
Now we subtract 1 from ShakeDuration, which controls how many shakes we want to make.
If ShakeDuration = 0, then we need to stop shaking, but we can’t leave the component as it is, because it will be rotated.
So we do one last rotate to angle 0 to leave it straight.
And lastly we turn off the timer, to stop the effect.