< Unit 3 - Interactive Animations and Games ('24-'25)

Lesson 8: Sprites

45 minutes

Overview

In order to create more interesting and detailed images, students are introduced to the sprite object which allows for one variable name to control both the shape and all its aspects. The lesson starts with a discussion of the various information that programs must keep track of, then presents sprites as a way to keep track of that information. Students then learn how to assign each sprite an image, which will greatly increase the complexity of what they can draw on the screen.

Question of the Day: How can we use sprites to help us keep track of lots of information in our programs?

CSTA K-12 Computer Science Standards (2017)
    • 2-AP-11 - Create clearly named variables that represent different data types and perform operations on their values.
    • 2-AP-13 - Decompose problems and subproblems into parts to facilitate the design, implementation, and review of programs.
    • 2-AP-16 - Incorporate existing code, media, and libraries into original programs, and give attribution.
    • 2-AP-17 - Systematically test and refine programs using a range of test cases.
    • 2-AP-19 - Document programs in order to make them easier to follow, test, and debug.

Agenda

Objectives

Students will be able to:
  • Create and use a sprite

Preparation

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the teachers
For the students

Vocabulary

  • Sprite - A character on the screen with properties that describe its location, movement, and look.

Teaching Guide

Warm Up (5 minutes)

How Much Information?

Review: So far we've written programs that put simple shapes on the screen. List of all of the different pieces of information that you have used to control how these shapes are drawn.

Prompt:If you wanted to create programs with more detailed images, maybe even characters that you could interact with, what other pieces of information might you need in your code?

Share: Allow students to share out their lists.

Discussion Goal: The goal here is to get students thinking about all of the different values that go into drawing a single shape on the screen, and how many more values they may need to control a more detailed character in a program. If students are struggling to come up with ideas, you might use some of the following prompts:

  • How do you tell a shape where to go on the screen?
  • How do you tell a shape what size it needs to be?
  • How do you tell a shape what color it should be? What about its outline?
  • What if you wanted to change any of those values during your program, or control other things like rotation?

Remarks

Today we'll learn how to create characters in our animations called sprites. These sprites will help us keep track of all of the information that we need in our programs.

Question of the Day: How can we use sprites to help us keep track of lots of information in our programs?

Activity (35 minutes)

Introduction to Sprites

Transition: Send students to Code Studio

Teaching Tip

Guide to Programming Levels: Additional guidance for programming levels is provided in the CSD Guide to Programming Levels. This document includes strategies and best-practices for facilitating programming levels with students.

Video: Show students the Introduction to Sprites video in the slides.

Questions to Consider with Video:

  • What is a sprite?
  • What problem do sprites solve?

Discussion Goal: From the video, students should think of sprites as a container that helps us manage different properties of an image and helps us solve the problem of organizing a lot of information about how something should be drawn to a screen. It's okay if students also bring in some of their own experiences with animations and sprites, but emphasize that in Game Lab: a sprite isn't the animation or image itself, but the container that we can attach an image to. This helps manage expectations in the next few levels, where a sprite is just a gray rectangle until we learn to add animations to it.

Teaching Tip

To encourage active engagement and reflection, use one or more of the strategies discussed in the Guide to Curriculum Videos.

Remarks

Keeping track of many shapes and the different variables that control characteristics of those shapes can get very complex. Computer scientists created something called an object which allows for one variable name to control both the shape and all its additional characteristics. In Game Lab, students will use a certain type of object called a sprite. A sprite is just a rectangle with properties for controlling its look.

Content Corner

Sprites and Objects: Behind the scenes, a sprite is a type of data called an object. Objects are programming structures that encapsulate data and behaviors into a single item. We don't need to introduce the formal idea of an object in this unit, but sprites are a good example of an object and students will learn to manipulate their properties throughout the unit.

Key Vocabulary:

  • Sprite - A character on the screen with properties that describe its location, movement, and look.

Video: Show students the The Animation Tab video in the slides.

Questions to Consider with Video:

  • What are the steps to adding an image to a sprite?

Discussion Goal: Make sure students understand that they will need to both create the image (or animation) in the Animation Tab and then add the animation to the sprite using the setAnimation() block. Students may be confused by the use of the word "animation" for single images, but in Game Lab, still images are considered "animations" with only one frame.

Teaching Tip

Misconception Alert! Many students may now confuse the concepts of a sprite, its animation, and the image that it draws to the screen. In the next few lessons, watch out for this misconception, and reinforce the idea that a sprite's animation is just one of its properties, the one that controls what image is drawn to the screen. Remind students that a single sprite may have different animations throughout the course of the program, and that two or more sprites might share the same animation.

Check for Understanding

Practice

Assessment

Assessment Opportunity

Formative Assessment: This level can be used as a formative assessment. A rubric is provided in the level, and written feedback can be given to students. Click here to learn more about giving feedback to students.

Challenges

Wrap Up (5 minutes)

Key Vocabulary:

  • Sprite - A character on the screen with properties that describe its location, movement, and look.

Journal

Question of the Day: How can we use sprites to help us keep track of lots of information in our programs?

Prompt: So far we've been able to change a sprite's location and image. What else might you want to change about your sprites?

Share: Allow students to share out their ideas.

Discussion Goal: This discussion prompts students to think about the different properties that a sprite might have, and prepares them for the next lesson, which explicitly covers sprite properties.

Creative Commons License (CC BY-NC-SA 4.0).

This work is available under a Creative Commons License (CC BY-NC-SA 4.0).

If you are interested in licensing Code.org materials for commercial purposes contact us.