An animation uses a series of pictures to create the illusion of smooth movement. Each individual picture is called a frame. You'll usually need to see at least several frames a second for the movement to look smooth.
To create animations, you'll need a way to keep drawing frame after frame. In Game Lab, this is done using the draw
function. The way programs run in Game Lab is
draw
draw
over and over again, 30 times a secondEach time the code inside draw
runs is like a new page in a flipbook. By making small changes to what's drawn each time, you can use Game Lab to create animations.
Code | Animation |
---|---|
This program sets the fill color and turns off the stroke outside the draw loop, then runs the code inside draw
over and over. The program will keep drawing dots in random locations forever.
Code | Animation |
---|---|
This program creates a sprite and sets its animation outside the draw loop. Then it repeatedly gives the sprite a new x location and redraws the orange background and the sprite to make it move.
Found a bug in the documentation? Let us know at documentation@code.org