Timed Activity: How do you repeat an action, pausing between each iteration?

How do you program time? How do you program animation? With many programming languages, concepts like animation are pushed back in the curriculum-- you might not get there until a year or two of coursework. With App Inventor’s event-based approach, you can explore timed activity and animation as a beginner. The high-level Clock component serves as an alarm clock, and you use its Timer event to trigger timed activity. Check out the following examples:

Example 1. How do you play a sound every second?

When theClock.Timerevent is triggered repeatedly. Think of it like an alarm clock. TheClock.TimerIntervalproperty, determines how often the sound will play. By default it is 1000 milliseconds (1 second), so if you don’t change it the sound above will play every second. You can set this property in the designer or with blocks.

Timed Activity: How do you repeat an action, pausing between each iteration?

How do you program time? How do you program animation? With many programming languages, concepts like animation are pushed back in the curriculum-- you might not get there until a year or two of coursework. With App Inventor’s event-based approach, you can explore timed activity and animation as a beginner. The high-level Clock component serves as an alarm clock, and you use its Timer event to trigger timed activity. Check out the following examples:

Example 2. How do you play a sound every 5 seconds?

The Clock.TimerIntervalproperty determines how often theClock.Timerevent triggers. By default, the timer interval is set to 1000 ms, or 1 second. If you set it to 5000, theClock.Timerevent will trigger every 5 seconds. It is a bit confusing and indirect, because you typically set theTimerIntervalin the Designer, and thewhen Clock.Timer eventis in the blocks editor. But just realize that the timer will be triggered every “TimerInterval” milliseconds.

Timed Activity: How do you repeat an action, pausing between each iteration?

How do you program time? How do you program animation? With many programming languages, concepts like animation are pushed back in the curriculum-- you might not get there until a year or two of coursework. With App Inventor’s event-based approach, you can explore timed activity and animation as a beginner. The high-level Clock component serves as an alarm clock, and you use its Timer event to trigger timed activity. Check out the following examples:

Example 3. How do you move a spaceship smoothly across the screen?

The spaceship’sXcoordinate defines its horizontal location. On each timer event, theXcoordinate is increased and the spaceship appears further to the right. If theClock.TimerIntervalproperty is set to the default of 1000 ms, then the ship will move every one second, a very choppy motion. Typically, for this type of animation, you’ll set the timer interval to something like 40 ms.

Watch YouTube Video:

Timed Activity: How do you repeat an action, pausing between each iteration?

How do you program time? How do you program animation? With many programming languages, concepts like animation are pushed back in the curriculum-- you might not get there until a year or two of coursework. With App Inventor’s event-based approach, you can explore timed activity and animation as a beginner. The high-level Clock component serves as an alarm clock, and you use its Timer event to trigger timed activity. Check out the following examples:

Example 4. A "moving picture" is really a sequence of pictures displayed very fast. The frame rate of a moving picture is the number of pictures (frames) shown every second. If you set the timer interval for the spaceship to 40 ms, what will be the frame rate for your “movie”? What is the typical frame rate for a movie you see at the theater?

If the timer interval is set to 40 ms, the object will move every 40 ms.So each frame-- each new picture with the spaceship in a different location-- will appear for 40 ms. Frames per second is the number of frames that will appear in one second (1000 ms). Since each frame is 40 ms long, you’ll end up with 1000/40=25 frames per second.

The standard frame rate for the film industry is 24 frames per second, see details.