Introduction to Python

Activity: Tobi Walking Animation

Lesson 2: Animations

Now let's put it all together! In this activity, we will use Python code to animate Tobi walking across the Stage by switching between costumes and moving him step by step.

Tobi the bear shown in three positions across the Stage from left to right illustrating the walking animation path

Setting Up

  • Open PictoBlox and create a New File.
  • Select Python as the coding environment.
  • Make sure Tobi is on the Stage and has at least two walking costumes (Tobi Walking 1 and Tobi Walking 2).
  • Set a backdrop of your choice — the Forest backdrop works great!

How the Animation Works

An animation is created by rapidly switching between costumes while moving the sprite. We will use a loop to repeat the costume switch and movement many times, creating the illusion that Tobi is walking.

Diagram showing four animation frames — Tobi Walking 1, move, Tobi Walking 2, move — with arrows looping back to demonstrate how rapid switching creates animation

Writing the Script

Type the following Python code in the editor:

import time # Set starting position tobi.go_to(-180, -80) tobi.point_in_direction(90) tobi.set_size(60) # Walking animation loop for i in range(30): tobi.switch_costume("Tobi Walking 1") tobi.move(8) time.sleep(0.1) tobi.switch_costume("Tobi Walking 2") tobi.move(8) time.sleep(0.1)

Understanding the Code

Code Breakdown

LineWhat it Does
import timeImports the time module so we can use time.sleep()
tobi.go_to(-180, -80)Positions Tobi at the left side of the Stage
tobi.point_in_direction(90)Makes Tobi face right
tobi.set_size(60)Sets Tobi's size to 60%
for i in range(30)Repeats the loop 30 times
tobi.switch_costume("Tobi Walking 1")Switches to the first walking costume
tobi.move(8)Moves Tobi 8 steps forward
time.sleep(0.1)Waits 0.1 seconds before the next step

Running the Script

  • Click the Run button to execute the code.
  • Watch Tobi walk smoothly across the Stage!
  • Try changing the range(30) value to make Tobi walk further or shorter.
  • Try changing time.sleep(0.1) to make the animation faster or slower.
PictoBlox stage showing Tobi mid-walk in the forest backdrop with Python code visible in the editor
Save your file with the name Tobi Walking Animation before moving on!

Subscribe to our newsletter.

Get updates to news and events.