Sprites
A sprite is the name we give to a collection of values in Game Lab that represents a character in a story, animation, or game. A sprite can be stored in a variable with a label, but unlike values you've stored in variables before, such as numbers, a sprite lets you store many related values all under the same label
Creating a Sprite
You can create a new sprite using the createSprite()
block.
- The sprite as drawn on screen. In this case, our sprite is located at (200, 200), the center of the screen, and has been assigned the animation "bunny"
- The
createSprite()
block, which creates a new sprite at (200, 200) and assigns it to the variable labelmy_bunny
. Note that just creating the sprite doesn't yet draw it on the screen. That will happen later. - The
sprite.setAnimation()
block assigns an animation (or image) to the sprite. In this case, we're using an animation named "bunny", which was added in the animation tab. Notice that instead of the default variable namesprite
, we've updated this tomy_bunny.setAnimation()
so that it changes the animation of themy_bunny
sprite. - Because sprites are just values stored as variables, they don't automatically get drawn on the screen. The
drawSprites()
block tells Game Lab to draw all of the sprites that have been created onto the screen.