Home

Awesome

<img src="docs/images/pyxel_logo_152x64.png">

Downloads GitHub Repo stars GitHub forks GitHub Sponsors

ko-fi

[ English | 中文 | Deutsch | Español | Français | Italiano | 日本語 | 한국어 | Português | Русский | Türkçe | Українська ]

Pyxel is a retro game engine for Python.

Thanks to its simple specifications inspired by retro gaming consoles, such as only 16 colors can be displayed and only 4 sounds can be played back at the same time, you can feel free to enjoy making pixel art style games.

<img src="docs/images/pyxel_message.png" width="480">

The motivation for the development of Pyxel is the feedback from users. Please give Pyxel a star on GitHub!

<p> <a href="https://kitao.github.io/pyxel/wasm/examples/10_platformer.html"> <img src="docs/images/10_platformer.gif" width="290"> </a> <a href="https://kitao.github.io/pyxel/wasm/examples/30sec_of_daylight.html"> <img src="docs/images/30sec_of_daylight.gif" width="350"> </a> <a href="https://kitao.github.io/pyxel/wasm/examples/02_jump_game.html"> <img src="docs/images/02_jump_game.gif" width="330"> </a> <a href="https://kitao.github.io/pyxel/wasm/examples/megaball.html"> <img src="docs/images/megaball.gif" width="310"> </a> <a href="https://kitao.github.io/pyxel/wasm/examples/image_editor.html"> <img src="docs/images/image_tilemap_editor.gif" width="320"> </a> <a href="https://kitao.github.io/pyxel/wasm/examples/sound_editor.html"> <img src="docs/images/sound_music_editor.gif" width="320"> </a> </p>

Pyxel's specifications and APIs are inspired by PICO-8 and TIC-80.

Pyxel is open source and free to use. Let's start making a retro game with Pyxel!

Specifications

Color Palette

<img src="docs/images/05_color_palette.png"> <img src="docs/images/pyxel_palette.png">

How to Install

Windows

After installing Python3 (version 3.8 or higher), run the following command:

pip install -U pyxel

If you install Python using the official installer, please check the Add Python 3.x to PATH checkbox to enable pyxel command.

Mac

After installing Homebrew, run the following commands:

brew install pipx
pipx ensurepath
pipx install pyxel

To update the version after installing Pyxel, run pipx upgrade pyxel.

Linux

After installing the SDL2 package (libsdl2-dev for Ubuntu), Python3 (version 3.8 or higher), and python3-pip, run the following command:

sudo pip3 install -U pyxel

If the above doesn't work, try self-building according to the instructions in Makefile.

Web

The web version of Pyxel does not require Python or Pyxel installation and runs on PCs as well as smartphones and tablets with supported web browsers.

For specific instructions, please refer to this page.

Try Pyxel Examples

After installing Pyxel, the examples of Pyxel will be copied to the current directory with the following command:

pyxel copy_examples

The examples to be copied are as follows:

<table> <tr> <td>01_hello_pyxel.py</td> <td>Simplest application</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/01_hello_pyxel.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/01_hello_pyxel.py">Code</a></td> </tr> <tr> <td>02_jump_game.py</td> <td>Jump game with Pyxel resource file</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/02_jump_game.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/02_jump_game.py">Code</a></td> </tr> <tr> <td>03_draw_api.py</td> <td>Demonstration of drawing APIs</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/03_draw_api.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/03_draw_api.py">Code</a></td> </tr> <tr> <td>04_sound_api.py</td> <td>Demonstration of sound APIs</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/04_sound_api.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/04_sound_api.py">Code</a></td> </tr> <tr> <td>05_color_palette.py</td> <td>Color palette list</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/05_color_palette.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/05_color_palette.py">Code</a></td> </tr> <tr> <td>06_click_game.py</td> <td>Mouse click game</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/06_click_game.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/06_click_game.py">Code</a></td> </tr> <tr> <td>07_snake.py</td> <td>Snake game with BGM</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/07_snake.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/07_snake.py">Code</a></td> </tr> <tr> <td>08_triangle_api.py</td> <td>Demonstration of triangle drawing APIs</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/08_triangle_api.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/08_triangle_api.py">Code</a></td> </tr> <tr> <td>09_shooter.py</td> <td>Shoot'em up game with screen transition</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/09_shooter.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/09_shooter.py">Code</a></td> </tr> <tr> <td>10_platformer.py</td> <td>Side-scrolling platform game with map</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/10_platformer.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/10_platformer.py">Code</a></td> </tr> <tr> <td>11_offscreen.py</td> <td>Offscreen rendering with Image class</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/11_offscreen.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/11_offscreen.py">Code</a></td> </tr> <tr> <td>12_perlin_noise.py</td> <td>Perlin noise animation</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/12_perlin_noise.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/12_perlin_noise.py">Code</a></td> </tr> <tr> <td>13_bitmap_font.py</td> <td>Drawing a bitmap font</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/13_bitmap_font.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/13_bitmap_font.py">Code</a></td> </tr> <tr> <td>14_synthesizer.py</td> <td>Synthesizer utilizing audio expantion features</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/14_synthesizer.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/14_synthesizer.py">Code</a></td> </tr> <tr> <td>15_tiled_map_file.py</td> <td>Loading and drawing a Tile Map File (.tmx)</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/15_tiled_map_file.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/15_tiled_map_file.py">Code</a></td> </tr> <tr> <td>16_transform.py</td> <td>Image rotation and scaling</td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/16_transform.html">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/16_transform.py">Code</a></td> </tr> <tr> <td>99_flip_animation.py</td> <td>Animation with flip function (non-web platforms only)</td> <td><a href="https://github.com/kitao/pyxel/blob/main/docs/images/99_flip_animation.gif">Demo</a></td> <td><a href="https://github.com/kitao/pyxel/blob/main/python/pyxel/examples/99_flip_animation.py">Code</a></td> </tr> <tr> <td>30sec_of_daylight.pyxapp</td> <td>1st Pyxel Jam winning game by <a href="https://x.com/helpcomputer0">Adam</a></td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/30sec_of_daylight.html">Demo</a></td> <td><a href="https://github.com/kitao/30sec_of_daylight">Code</a></td> </tr> <tr> <td>megaball.pyxapp</td> <td>Arcade ball physics game by <a href="https://x.com/helpcomputer0">Adam</a></td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/megaball.html">Demo</a></td> <td><a href="https://github.com/helpcomputer/megaball">Code</a></td> </tr> <tr> <td>8bit-bgm-gen.pyxapp</td> <td>Background music generator by <a href="https://x.com/frenchbread1222">frenchbread</a></td> <td><a href="https://kitao.github.io/pyxel/wasm/examples/8bit-bgm-gen.html">Demo</a></td> <td><a href="https://github.com/shiromofufactory/8bit-bgm-generator">Code</a></td> </tr> </table>

An examples can be executed with the following commands:

cd pyxel_examples
pyxel run 01_hello_pyxel.py
pyxel play 30sec_of_daylight.pyxapp

How to Use

Create Pyxel Application

After importing the Pyxel module in your python script, specify the window size with init function first, then starts the Pyxel application with run function.

import pyxel

pyxel.init(160, 120)

def update():
    if pyxel.btnp(pyxel.KEY_Q):
        pyxel.quit()

def draw():
    pyxel.cls(0)
    pyxel.rect(10, 10, 20, 20, 11)

pyxel.run(update, draw)

The arguments of run function are update function to update each frame and draw function to draw screen when necessary.

In an actual application, it is recommended to wrap pyxel code in a class as below:

import pyxel

class App:
    def __init__(self):
        pyxel.init(160, 120)
        self.x = 0
        pyxel.run(self.update, self.draw)

    def update(self):
        self.x = (self.x + 1) % pyxel.width

    def draw(self):
        pyxel.cls(0)
        pyxel.rect(self.x, 0, 8, 8, 9)

App()

When creating simple graphics without animation, show function can be used to make the code more concise.

import pyxel

pyxel.init(120, 120)
pyxel.cls(1)
pyxel.circb(60, 60, 40, 7)
pyxel.show()

Run Pyxel Application

A created Python script can be executed using the python command:

python PYTHON_SCRIPT_FILE

It can also be run with the pyxel run command:

pyxel run PYTHON_SCRIPT_FILE

Additionally, the pyxel watch command enables monitoring of changes in a specified directory, automatically re-running the program when changes are detected:

pyxel watch WATCH_DIR PYTHON_SCRIPT_FILE

Directory monitoring can be stopped by pressing Ctrl(Command)+C.

Special Controls

The following special controls can be performed while a Pyxel application is running:

How to Create Resources

Pyxel Editor can create images and sounds used in a Pyxel application.

It starts with the following command:

pyxel edit PYXEL_RESOURCE_FILE

If the specified Pyxel resource file (.pyxres) exists, the file is loaded, and if it does not exist, a new file is created with the specified name. If the resource file is omitted, the name is my_resource.pyxres.

After starting Pyxel Editor, the file can be switched by dragging and dropping another resource file.

The created resource file can be loaded with load function.

Pyxel Editor has the following edit modes.

Image Editor

The mode to edit the image banks.

<a href="https://kitao.github.io/pyxel/wasm/examples/image_editor.html"> <img src="docs/images/image_editor.gif"> </a>

Drag and drop an image file (PNG/GIF/JPEG) onto the Image Editor to load the image into the currently selected image bank.

Tilemap Editor

The mode to edit tilemaps in which images of the image banks are arranged in a tile pattern.

<a href="https://kitao.github.io/pyxel/wasm/examples/tilemap_editor.html"> <img src="docs/images/tilemap_editor.gif"> </a>

Drag and drop a TMX file (Tiled Map File) onto the Tilemap Editor to load its layer in the drawing order that corresponds to the currently selected tilemap number.

Sound Editor

The mode to edit sounds.

<a href="https://kitao.github.io/pyxel/wasm/examples/sound_editor.html"> <img src="docs/images/sound_editor.gif"> </a>

Music Editor

The mode to edit musics in which the sounds are arranged in order of playback.

<a href="https://kitao.github.io/pyxel/wasm/examples/music_editor.html"> <img src="docs/images/music_editor.gif"> </a>

Other Resource Creation Methods

Pyxel images and tilemaps can also be created by the following methods:

Pyxel sounds can also be created in the following method:

Please refer to the API reference for usage of these functions.

How to Distribute Applications

Pyxel supports a dedicated application distribution file format (Pyxel application file) that works across platforms.

Create the Pyxel application file (.pyxapp) with the pyxel package command:

pyxel package APP_DIR STARTUP_SCRIPT_FILE

If the application should include resources or additional modules, place them in the application directory.

Metadata can be displayed at runtime by specifying it in the following format within the startup script. Fields other than title and author can be omitted.

# title: Pyxel Platformer
# author: Takashi Kitao
# desc: A Pyxel platformer example
# site: https://github.com/kitao/pyxel
# license: MIT
# version: 1.0

The created application file can be executed with the pyxel play command:

pyxel play PYXEL_APP_FILE

Pyxel application file also can be converted to an executable or an HTML file with the pyxel app2exe or pyxel app2html commands.

API Reference

System

Resource

Input

Graphics

<img src="docs/images/blt_figure.png"> <img src="docs/images/bltm_figure.png">

Audio

Math

Image Class

Tilemap Class

Sound Class

Music Class

Advanced APIs

Pyxel has "advanced APIs" that are not mentioned in this reference because they "may confuse users" or "need specialized knowledge to use".

If you are familiar with your skills, try to create amazing works with this as a clue!

How to Contribute

Submitting Issues

Use the Issue Tracker to submit bug reports and feature/enhancement requests. Before submitting a new issue, ensure that there is no similar open issue.

Manual Testing

Anyone manually testing the code and reporting bugs or suggestions for enhancements in the Issue Tracker are very welcome!

Submitting Pull Requests

Patches/fixes are accepted in form of pull requests (PRs). Make sure the issue the pull request addresses is open in the Issue Tracker.

Submitted pull request is deemed to have agreed to publish under MIT License.

Other Information

License

Pyxel is under MIT License. It can be reused within proprietary software, provided that all copies of the software or its substantial portions include a copy of the terms of the MIT License and also a copyright notice.

Recruiting Sponsors

Pyxel is looking for sponsors on GitHub Sponsors. Consider sponsoring Pyxel for continued maintenance and feature additions. Sponsors can consult about Pyxel as a benefit. Please see here for details.