Text of realpython.com › arcade-python-game-framework as Styx crawled it on Nov 20, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Arcade: A Primer on the Python Game Framework – Real Python

Arcade: A Primer on the Python Game Framework by Jon Fincher Updated Jan 15, 2020 Reading time estimate 44m intermediate gamedev Table of Contents Remove ads Computer games are a great way to introduce people to coding and computer science. Since I was a player in my youth, the lure of writing video games was the reason I learned to code. Of course, when I learned Python, my first instinct was to write a Python game .

While Python makes learning to code more accessible for everyone, the choices for video game writing can be limited, especially if you want to write arcade games with great graphics and catchy sound effects. For many years, Python game programmers were limited to the pygame framework. Now, there’s another choice. The arcade library is a modern Python framework for crafting games with compelling graphics and sound. Object-oriented and built for Python 3.6 and up, arcade provides the programmer with a modern set of tools for crafting great Python game experiences.

In this tutorial, you’ll learn how to: Install the arcade library Draw items on the screen Work with the arcade Python game loop Manage on-screen graphic elements Handle user input Play sound effects and music Describe how Python game programming with arcade differs from pygame This tutorial assumes you have an understanding of writing Python programs . Since arcade is an object-oriented library, you should also be familiar with object-oriented programming as well.

All of the code, images, and sounds for this tutorial are available for download at the link below: Download Assets: Click here to download the assets you’ll use to make a game with arcade in this tutorial. Background and Setup The arcade library was written by Paul Vincent Craven , a computer science professor at Simpson College in Iowa, USA. As it’s built on top of the pyglet windowing and multimedia library, arcade features various improvements, modernizations, and enhancements over pygame : Boasts modern OpenGL graphics Supports Python 3 type hinting Has better support for animated sprites Incorporates consistent command, function, and parameter names Encourages separation of game logic from display code Requires less boilerplate code Maintains more documentation , including complete Python game examples Has a built-in physics engine for platform games To install arcade and its dependencies, use the appropriate pip command: Language: Shell $ python -m pip install arcade On the Mac, you also need to install PyObjC : Language: Shell $ python -m pip install PyObjC arcade Complete installation instructions based on your platform are available for Windows , Mac , Linux , and even Raspberry Pi .

You can even install arcade directly from source if you’d prefer. Note: More recent versions of arcade utilize data classes , which are included in Python only for version 3.7 and later. However, a backport is available on PyPI for Python 3.6 that you can install using pip : Language: Shell $ python -m pip install dataclasses See The Ultimate Guide to Data Classes in Python 3.7 for more information. This tutorial assumes you’re using arcade 2.1 and Python 3.7 throughout.

Remove ads Basic arcade Program Before you dig in, let’s take a look at an arcade program that will open a window, fill it with white, and draw a blue circle in the middle: Language: Python 1 # Basic arcade program 2 # Displays a white window with a blue circle in the middle 3 4 # Imports 5 import arcade 6 7 # Constants 8 SCREEN_WIDTH = 600 9 SCREEN_HEIGHT = 800 10 SCREEN_TITLE = "Welcome to Arcade" 11 RADIUS = 150 12 13 # Open the window 14 arcade . open_window ( SCREEN_WIDTH , SCREEN_HEIGHT , SCREEN_TITLE ) 15 16 # Set the background color 17 arcade . set_background_color ( arcade . color .

WHITE ) 18 19 # Clear the screen and start drawing 20 arcade . start_render () 21 22 # Draw a blue circle 23 arcade . draw_circle_filled ( 24 SCREEN_WIDTH / 2 , SCREEN_HEIGHT / 2 , RADIUS , arcade . color . BLUE 25 ) 26 27 # Finish drawing 28 arcade . finish_render () 29 30 # Display everything 31 arcade . run () When you run this program, you’ll see a window that looks like this: Let’s break this down line by line: Line 5 imports the arcade library.

Without this, nothing else works. Lines 8 to 11 define some constants you’ll use a little later, for clarity. Line 14 opens the main window. You provide the width, height, and title bar text, and arcade does the rest. Line 17 sets the background color using a constant from the arcade.color package. You can also specify an RGB color using a list or tuple . Line 20 sets arcade into drawing mode. Anything you draw after this line will be shown on the screen.

Lines 23 to 25 draw the circle by providing the center X and Y coordinates, the radius, and the color to use. Line 28 ends drawing mode. Line 31 displays your window for you to see. If you’re familiar with pygame , then you’ll notice a few things are different: There is no pygame.init() . All initialization is handled when you run import arcade . There is no explicitly-defined display loop. It’s handled in arcade.run() .

There is no event loop here, either. Again, arcade.run() handles events and provides some default behaviors, such as the ability to close the window. You can use pre-defined colors for drawing rather than defining them all yourself. You have to start and finish drawing in arcade using start_render() and finish_render() . Let’s take a close look at the fundamental arcade concepts behind this program. arcade Concepts Like pygame , arcade code runs on almost every platform that supports Python.

This requires arcade to deal with abstractions for various hardware differences on those platforms. Understanding these concepts and abstractions will help you design and develop your own games while understanding how arcade differs from pygame will help you adapt to its unique point of view. Initialization Since it deals with a variety of platforms, arcade must perform an initialization step before you can use it. This step is automatic and occurs whenever you import arcade , so there’s no additional code you need to write.

When you import it, arcade does the following: Verify that you’re running on Python 3.6 or higher. Import the pyglet_ffmeg2 library for sound handling, if it’s available. Import the pyglet library for window and multimedia handling. Set up constants for colors and key mappings. Import the remaining arcade library. Contrast this with pygame , which requires a separate initialization step for each module. Windows and Coordinates Everything in arcade happens in a window, with you create using open_window() .

Currently, arcade only supports a single display window. You can make the window resizable when you open it. arcade uses the same Cartesian coordinate system you may have learned in algebra class. The window lives in quadrant I , with the origin point (0, 0) located in the lower-left corner of the screen. The x coordinate increases as you move right, and the y coordinate increases as you move up: It’s important to note that this behavior is the opposite of pygame and many other Python game frameworks.

It may take some time for you to adjust to this difference. Remove ads Drawing Out of the box, arcade has functions for drawing various geometric shapes, including: Arcs Circles Ellipses Lines Parabolas Points Polygons Rectangles Triangles All of the drawing functions begin with draw_ and follow a consistent naming and parameter pattern. There are different functions for drawing filled and outlined shapes: Because rectangles are common, there are three separate functions for drawing them in different ways: draw_rectangle() expects the x and y coordinates of the center of the rectangle, the width, and the height. draw_lrtb_rectangle() expects the left and right x coordinates, followed by the top and bottom y coordinates. draw_xywh_rectangle() uses the x and y coordinates of the bottom-left corner, followed by the widt

The rest of this page is on the live site.