Step 6: Creating Our Animation Loop

Goal:


Let’s create a loop that will help us run our health damage indicator for two seconds in the game.

Steps:

  1. Still on the “Sharky” sprite, add the following code.
  2. From Events, grab a when I receive block and change it to “HealthLost!”
  3. From Variables, place a set to block and change it to sadAnimationTime and set the number to 2.
  4. From Control, place a repeat until block.
  5. From Operators, place a < block inside the repeat until block.
  6. From Variables, place a round sadAnimationTime block to the left of the < block and set the right side to 1.
  7. From Control, place a wait 1 seconds block.
  8. From Variables, place a change by block and change it to sadAnimationTime and set the number to -1.

Code: