Skip to content
Projects

About

A game engine like Scratch.

Games & Emulation

How these counts are measured

Measured star growth

in 24h
0
in 7 days
-1
in 15 days
-1
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README_en.md

Original

Scrawl - A Scratch-like Python Game Engine

中文 | English

Scrawl logo

Rust and Bevy PyPI version GPL-3.0 license

Scrawl is a Python-facing 2D game engine. It keeps the Scratch-style model of sprites, scenes, clones, broadcasts, and events while Rust and Bevy own the window, rendering, input, audio, and ECS runtime.

Starting with 2.2, scrawl is the only supported package and mainline API. The old Pygame backend and the scrawl_v2 import path have been removed.

Features

  • Scratch-like Game, Scene, and Sprite2D model with clones and broadcasts.
  • Coroutine tasks where a yielded number is a delay in milliseconds.
  • Decorators for keyboard, mouse, sprite clicks, broadcasts, and collisions.
  • Native Rust/Bevy window, renderer, input, audio, and fixed-step runtime.
  • Shape and PNG/SVG sprites with visibility, scale, explicit dimensions, and z_index.
  • Persistent text, speech, pen trails, sound effects, music, and scene switching.
  • Dirty property synchronization so idle sprites do not resend every render property each frame.
  • A unified startup scene tree for Scene, Node, Node2D, and Sprite2D hierarchy mapping.
  • Runtime tree sync for Node2D transform, layer, and visibility changes plus node add, remove, same-scene reparent, and clone operations through one bridge queue.
  • A visual IDE with scene editing, an inspector, code editing, running, and an AI assistant.

Node, Node2D, Sprite2D, and the core physics nodes are connected to NativeGame; UI, TileMap, Particles, and Navigation are still being integrated. Check the runtime capability table before depending on them.

Installation

Scrawl requires Python 3.8 or newer.

python -m pip install scrawl-engine

Upgrade an existing installation:

python -m pip install --upgrade scrawl-engine

Building from source also requires stable Rust:

git clone https://github.com/streetartist/scrawl.git
cd scrawl
python -m pip install -r requirements-dev.txt
python -m maturin develop --release
python -c "import scrawl; print(scrawl.__version__)"

Quick Start

from scrawl import Game, Scene, Sprite2D, as_main, on_edge_collision, on_key


class Ball(Sprite2D):
    def __init__(self):
        super().__init__()
        self.name = "Ball"
        self.position = (400, 300)
        self.direction = 45
        self.color = (84, 193, 189)
        self.set_dimensions(48, 48)

    @as_main
    def move_forever(self):
        while True:
            self.move(3)
            yield 16

    @on_edge_collision("any")
    def bounce(self):
        self.turn_right(180)


class Player(Sprite2D):
    def __init__(self):
        super().__init__()
        self.name = "Player"
        self.position = (200, 200)
        self.color = (240, 106, 95)
        self.set_dimensions(56, 40)
        self.z_index = 1

    @on_key("w", "held")
    def up(self):
        self.move_up(5)

    @on_key("s", "held")
    def down(self):
        self.move_down(5)

    @on_key("a", "held")
    def left(self):
        self.move_left(5)

    @on_key("d", "held")
    def right(self):
        self.move_right(5)


class MainScene(Scene):
    def __init__(self):
        super().__init__("main")
        self.set_background_color(25, 32, 43)
        self.add_child(Ball())
        self.add_child(Player())


game = Game(width=800, height=600, title="My Scrawl Game")
game.set_scene(MainScene())
game.run(fps=60, debug=True)

The coordinate origin is at the bottom left. X increases to the right and Y increases upward. Directions use compass degrees: 0 points up and 90 points right.

Run the repository examples with:

python examples/basic_movement.py
python examples/node_hierarchy.py
python examples/witch.py

The witch example demonstrates costume animation, clones, collisions, broadcasts, and persistent text. Costumes are filesystem paths; Pygame Surface objects are no longer supported.

The node hierarchy example covers startup hierarchy mapping plus runtime Node2D property sync, subtree creation, reparenting, and removal.

Core Concepts

Game and Scene

Game creates the native window, stores scenes, and starts the Bevy loop. Scene is the node-tree root and manages child nodes, its background, and broadcasts.

game = Game(width=1280, height=720, title="Game title", fps=60)
game.set_scene(MainScene("main"))
game.add_scene(PauseScene("pause"))
game.run(debug=False, vsync=True)

Sprite2D

Sprite2D is currently the most complete visual node in the native runtime.

Area API
Transform position, x, y, direction, size, move(), go_to(), point_towards()
Appearance color, visible, width, height, z_index, set_dimensions()
Costumes add_costume(), switch_costume(), next_costume()
Lifecycle clone(), delete_self()
Interaction say(), set_text(), broadcast(), play_sound()
Pen pen_down(), pen_up(), set_pen_color(), set_pen_size()

Costumes must be filesystem paths:

self.add_costume("idle", "assets/player-idle.svg")
self.add_costume("walk", "assets/player-walk.png")
self.switch_costume("walk")

Events and Coroutines

Handlers may be regular functions or generators. The runtime resumes a generator after the number of milliseconds it yields.

@as_main
def main_task(self):
    while True:
        self.next_costume()
        yield 200

@as_clones
def clone_task(self):
    self.show()
    while True:
        self.move(5)
        yield 16

@on_key("space", "pressed")
def fire(self):
    self.clone(self.projectile)

@on_mouse(1, "pressed")
def mouse_down(self):
    self.say("clicked")

@on_sprite_clicked
def selected(self):
    self.color = (255, 200, 80)

@on_broadcast("game_over")
def game_over(self):
    self.set_text("Game Over", 36, (255, 255, 255))

@on_edge_collision("any")
def hit_edge(self):
    self.delete_self()

@on_sprite_collision("Enemy")
def hit_enemy(self):
    self.broadcast("lose_life")

Keys use string identifiers such as "space", "left", and "a". Event modes are "pressed", "released", or "held".

Text, Pen, and Audio

self.say("Hello", duration=1500)
self.set_text("Score: 10", font_size=24, color=(255, 240, 120))
self.set_pen_color(255, 80, 80)
self.set_pen_size(3)
self.pen_down()
self.move(100)
self.pen_up()

game.load_sound("jump", "assets/jump.ogg")
game.load_music("bgm", "assets/background.ogg")
game.play_sound("jump")
game.play_music("bgm", loops=-1, volume=0.7)
game.stop_music()

Visual IDE

scrawl_ide provides a scene tree, inspector, code editor, runner, and an OpenAI-compatible AI assistant. It is still under active development, so keep generated projects under version control.

python -m pip install -r scrawl_ide/requirements.txt
python scrawl_ide/main.py

Configure the AI endpoint, model, and API key in the IDE settings. Credentials are not written into generated game source files.

Repository Layout

crates/              Rust engine crates and PyO3 bridge
python/scrawl/       The only supported Python package
examples/            Runnable examples and assets for the current API
scrawl_ide/          Visual IDE
docs/                Manual, migration guide, release notes, and roadmap
tests/               Python API tests

Documentation

Development and Verification

cargo check -p scrawl-bridge
cargo test -p scrawl-bridge
python -m unittest discover -s tests -v
git diff --check

GitHub issues and pull requests are welcome at https://github.com/streetartist/scrawl. The QQ group is 1001578435.

Scrawl is released under the GNU General Public License v3.0.

Explore related projects

Loading…