The SVG Game Engine is a revolutionary 2D game development framework that compiles Python game code into standalone SVG files. Unlike traditional game engines that require runtime environments or plugins, games built with SVG Engine run entirely within modern web browsers using native SVG capabilities.
Entire games compile to single SVG files that are typically under 100KB
Write games in Python with a simple, intuitive API that compiles to SVG
Runs anywhere SVG is supported - no plugins or downloads required
The SVG Engine transforms Python game code into optimized SVG markup with embedded JavaScript. The compilation process includes:
The SVG Engine requires Python 3.8 or higher. Install it via pip:
my_game.py)
Use the --debug flag during development to include
error messages and performance stats in your compiled SVG.
| Function | Description | Example |
|---|---|---|
| create_window(width, height) | Initialize game window | create_window(800, 600) |
| set_title(title) | Set window title | set_title("My Game") |
| load_image(path) | Load image asset | img = load_image("char.png") |
| key_pressed(key) | Check if key is pressed | if key_pressed("space"): |
| mouse_position() | Get current mouse position | x, y = mouse_position() |
Sprites are the fundamental building blocks of games in SVG Engine. They represent visual elements that can be moved,
rotated, scaled, and animated. Under the hood, sprites compile to SVG <image>
or <g> elements with transform attributes.
| Property | Type | Description |
|---|---|---|
| x, y | number | Position coordinates |
| scale_x, scale_y | number | Horizontal/vertical scale |
| rotation | degrees | Rotation angle |
| opacity | 0.0-1.0 | Transparency level |
| visible | boolean | Visibility flag |
SVG Engine provides powerful animation capabilities that compile to efficient SVG SMIL animations and CSS transitions. Animations can be defined declaratively or controlled programmatically.
The compilation process transforms your Python game into a standalone SVG file containing all game logic, assets, and animations. This section covers advanced compilation options and optimization techniques.
| Option | Description | Example |
|---|---|---|
| --optimize | Enable size optimization | svg-compile --optimize |
| --minify | Minify JavaScript code | svg-compile --minify |
| --external-assets | Keep assets as external files | svg-compile --external-assets |
| --fps | Set target framerate | svg-compile --fps 30 |
| --size | Override window size | svg-compile --size 1024x768 |
SVG Engine is optimized for lightweight 2D games. While it can handle moderately complex games, it's best suited for casual games, interactive art, and educational projects. For very complex games with thousands of objects, a traditional game engine might be more appropriate.
SVG games work in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera. Mobile browsers on both iOS and Android are also supported. Internet Explorer has limited support (IE11 works but with some feature restrictions).
SVG rendering is generally slower than Canvas or WebGL for complex scenes, but offers excellent performance for typical 2D games with dozens to hundreds of elements. The advantage is that SVG provides resolution-independent graphics and easy DOM manipulation.
Yes! SVG Engine is MIT licensed, which means you can create commercial games with it. The compiled SVG files are yours to distribute however you like - on your website, app stores (wrapped in a web view), or as standalone files.
SVG games can use the browser's localStorage API to save game state. The engine provides
helper functions like save_data(key, value)
and load_data(key) to simplify this process.
Join our community forum to ask questions and share your SVG game projects!
Visit Community