L7 Draw Loop

Post date: May 29, 2020 11:29:30 PM

Overview

This lesson introduces the draw loop, one of the core programming paradigms in Game Lab. The class combines the draw loop with random numbers to manipulate some simple animations with dots and then with sprites. Afterward, everyone uses what they learned to update the sprite scene from the previous lesson.

Vocab

Animation - a series of images that create the illusion of motion by being shown rapidly one after the other

Frame - a single image within an animation

Frame Rate - the rate at which frames in an animation are shown, typically measured in frames per second

New Code

Remember how a flipbook shows a series of images that are slightly different? The blurring of these images when shown one after another creates and animation. The previous lesson a sprite was ".setAnimation(Character) and this time we can have sprite change its image. Think of it as costume changes and each costume is a different position.Remember when you draw a shape, you need to define its fill "Color" and other properties before it will create the shape.Frame Rate: the frequency at which frames in a television picture, film, or video sequence are displayed.Dot NotationNotice that all of the examples above follow a common pattern of sprite label. sprite property. We call this format dot notation. The first part will always be unique to the sprite that you want to modify, but and the second part will always be one of the properties common to all sprites.

Evaluate the code

The first Variable "World.frameRate gets the number 10"

The second Variable "salt gets the location 200 X, 200 Y"

Salt gets the animation picture salt.

The computer will then draw over and over a sky blue background, the salt's Y location will get a random number between 200 and 220. Each drawing the background will be drawn again and the salt will be drawn at a different Y location and we will see the salt shake up and down as the picture changes.