Downloads GitHub Repo stars GitHub forks GitHub Sponsors

ko-fi

[ [English](https://github.com/kitao/pyxel/blob/main//README.md) | [中文](https://github.com/kitao/pyxel/blob/main//docs/README.cn.md) | [Deutsch](https://github.com/kitao/pyxel/blob/main//docs/README.de.md) | [Español](https://github.com/kitao/pyxel/blob/main//docs/README.es.md) | [Français](https://github.com/kitao/pyxel/blob/main//docs/README.fr.md) | [Italiano](https://github.com/kitao/pyxel/blob/main//docs/README.it.md) | [日本語](https://github.com/kitao/pyxel/blob/main//docs/README.ja.md) | [한국어](https://github.com/kitao/pyxel/blob/main//docs/README.ko.md) | [Português](https://github.com/kitao/pyxel/blob/main//docs/README.pt.md) | [Русский](https://github.com/kitao/pyxel/blob/main//docs/README.ru.md) ]

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.

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

How to Install

Windows

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

sh pip install -U pyxel

Mac

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

sh pip3 install -U pyxel

Linux

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

sh sudo pip3 install -U pyxel

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

Try Pyxel Examples

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

sh pyxel copy_examples

The examples to be copied are as follows:

An examples can be executed with the following commands:

sh cd pyxel_examples pyxel run 01_hello_pyxel.py pyxel play 30SecondsOfDaylight.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.

```python 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:

```python 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() ```

It is also possible to write simple code using show function and flip function to draw simple graphics and animations.

show function displays the screen and waits until the Esc key is pressed.

```python import pyxel

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

flip function updates the screen once.

```python import pyxel

pyxel.init(120, 80)

while True: pyxel.cls(3) pyxel.rectb(pyxel.frame_count % 160 - 40, 20, 40, 40, 7) pyxel.flip() ```

Run Pyxel Application

The created Python script can be executed with the following command:

sh pyxel run PYTHON_SCRIPT_FILE

For the packaged version, it can be executed like a normal Python script:

sh cd pyxel_examples python3 PYTHON_SCRIPT_FILE

(For Windows, type python instead of python3)

Special Controls

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

How to Create Resource

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

It starts with the following command:

sh 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. If the resource file is dragged and dropped while holding down Ctrl(Cmd) key, only the resource type (Image/Tilemap/Sound/Music) that is currently being edited will be loaded. This operation enables to combine multiple resource files into one.

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.

By dragging and dropping an image file (png/gif/jpeg) onto the Image Editor screen, the image can be loaded 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.

Sound Editor:

The mode to edit sounds.

Music Editor:

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

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 Application

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

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

sh pyxel package APP_ROOT_DIR STARTUP_SCRIPT_FILE

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

The created application file can be executed with the following command:

sh pyxel play PYXEL_APP_FILE

API Reference

System

Resource

Input

Graphics

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 Issue

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 Request

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.