What’s a Sprite?#
Each sprite describes where a game object is & how to draw it. This includes:
Where it is in the world
Where to find the image data
How big the image should be
The rest of this page will explain using the
SpriteList class to draw
sprites to the screen.
They’re How Hardware Works#
Graphics hardware is designed to draw groups of objects at the same time. These groups are called batches.
This means that using fewer batches helps your game run faster, and that you should avoid trying to draw sprites one at a time.
They Help Develop Games Faster#
Sprite lists do more than just draw. They also have built-in features which save you time & effort, including:
Automatically skipping off-screen sprites
Debug drawing for hit boxes
Drawing with Sprites and SpriteLists#
Let’s get to the example code.
There are 3 steps to drawing sprites with a sprite list:
Create & append your
Spriteinstance(s) to the list
Here’s a minimal example:
1""" 2Minimal Sprite Example 3 4Draws a single sprite in the middle screen. 5 6If Python and Arcade are installed, this example can be run from the command line with: 7python -m arcade.examples.sprite_minimal 8""" 9import arcade 10 11 12class WhiteSpriteCircleExample(arcade.Window): 13 14 def __init__(self): 15 super().__init__(800, 600, "White SpriteCircle Example") 16 self.sprites = None 17 self.setup() 18 19 def setup(self): 20 # 1. Create the SpriteList 21 self.sprites = arcade.SpriteList() 22 23 # 2. Create & append your Sprite instance to the SpriteList 24 self.circle = arcade.SpriteCircle(30, arcade.color.WHITE) # 30 pixel radius circle 25 self.circle.position = self.width // 2, self.height // 2 # Put it in the middle 26 self.sprites.append(self.circle) # Append the instance to the SpriteList 27 28 def on_draw(self): 29 # 3. Call draw() on the SpriteList inside an on_draw() method 30 self.sprites.draw() 31 32 33if __name__ == "__main__": 34 game = WhiteSpriteCircleExample() 35 game.run()
Using Images with Sprites#
Beginners should see the following to learn more, such as how to load images into sprites:
Viewports, Cameras, and Screens#
Intermediate users can move past the limitations of
with the following classes: