Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions docs/api_reference/graphics/renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,31 @@ Draws a scaled multi-layer sprite.

### void drawTileMap(const TileMap& map, int originX, int originY, Color color)

Draws a tilemap.
Draws a 1bpp tilemap.

**Parameters:**
- `map` (const `TileMap&`): Tilemap descriptor (indices, tiles, dimensions)
- `originX` (int): X coordinate of the top-left corner of the tilemap
- `originY` (int): Y coordinate of the top-left corner of the tilemap
- `color` (`Color`): Color used for tile sprites
- `map` (const `TileMap&`): Tilemap descriptor (indices, 1bpp tiles, dimensions)
- `originX` (int): X coordinate of the top-left corner
- `originY` (int): Y coordinate of the top-left corner
- `color` (`Color`): Color used for all tiles in the map

### void drawTileMap(const TileMap2bpp& map, int originX, int originY)

Draws a 2bpp tilemap. Available when `PIXELROOT32_ENABLE_2BPP_SPRITES` is defined.

**Parameters:**
- `map` (const `TileMap2bpp&`): Tilemap descriptor (indices, 2bpp tiles, dimensions)
- `originX` (int): X coordinate
- `originY` (int): Y coordinate

### void drawTileMap(const TileMap4bpp& map, int originX, int originY)

Draws a 4bpp tilemap. Available when `PIXELROOT32_ENABLE_4BPP_SPRITES` is defined.

**Parameters:**
- `map` (const `TileMap4bpp&`): Tilemap descriptor (indices, 4bpp tiles, dimensions)
- `originX` (int): X coordinate
- `originY` (int): Y coordinate

**Performance Notes:**
- Very efficient for rendering large backgrounds
Expand Down
39 changes: 32 additions & 7 deletions docs/api_reference/graphics/tilemap.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
# TileMap

Structure for tile-based background rendering.
Generic structure for tile-based background rendering.

## Description

`TileMap` is a compact structure for rendering tile-based backgrounds efficiently. It uses 1bpp sprites as tiles and stores level data as a compact array of tile indices.
`TileMapGeneric<T>` is a template structure for rendering tile-based backgrounds efficiently. It supports multiple bit-depths (1bpp, 2bpp, 4bpp) by using the appropriate sprite type for tiles.

Tilemaps are ideal for large backgrounds, levels, and static environments. They support viewport culling (only visible tiles are drawn) for optimal performance.

## Namespace

```cpp
namespace pixelroot32::graphics {
struct TileMap {
template<typename T>
struct TileMapGeneric {
// ...
};

using TileMap = TileMapGeneric<Sprite>;
using TileMap2bpp = TileMapGeneric<Sprite2bpp>;
using TileMap4bpp = TileMapGeneric<Sprite4bpp>;
}
```

## Template Parameters

### T

The sprite type used for tiles.

**Supported types:**
- `Sprite` (1bpp)
- `Sprite2bpp` (2bpp)
- `Sprite4bpp` (4bpp)

## Structure

### uint8_t* indices
Expand Down Expand Up @@ -70,11 +86,11 @@ Height of the tilemap in tiles.
height = 16; // 16 tiles tall
```

### const Sprite* tiles
### const T* tiles

Array of tile sprites.
Array of tile sprites of type `T`.

**Type:** `const Sprite*`
**Type:** `const T*`

**Access:** Read-only

Expand All @@ -84,7 +100,7 @@ Array of tile sprites.
- All tiles should be the same size
- Should be stored in flash (const) for best performance

**Example:**
**Example (1bpp):**
```cpp
static const Sprite TILE_SPRITES[] = {
EMPTY_TILE, // Index 0
Expand All @@ -94,6 +110,15 @@ static const Sprite TILE_SPRITES[] = {
};
```

**Example (2bpp):**
```cpp
static const Sprite2bpp TILE_SPRITES_2BPP[] = {
TILE_GRASS, // Index 0
TILE_DIRT, // Index 1
// ... more tiles
};
```

### uint8_t tileWidth

Width of each tile in pixels.
Expand Down
Binary file modified docs/assets/images/favicon.ico
Binary file not shown.
Binary file modified docs/assets/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/images/logo_v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 28 additions & 18 deletions docs/manual/advanced_graphics/tilemaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,47 @@ A tilemap is a 2D grid where each cell references a tile sprite. Instead of plac
- **Easy level design**: Edit level data, not code
- **Fast rendering**: Optimized tilemap drawing
- **Large levels**: Create levels bigger than screen
- **Multiple Bit-Depths**: Support for 1bpp, 2bpp, and 4bpp tilemaps for higher graphical fidelity

## Creating a Tilemap

### 1. Define Tiles

First, create the tile sprites you'll reuse:
First, create the tile sprites you'll reuse. You can use standard 1bpp sprites or multi-bpp sprites (2bpp/4bpp) if enabled.

#### 1bpp Tiles Example
```cpp
#include <graphics/Renderer.h>

// Empty tile (transparent)
static const uint16_t TILE_EMPTY_BITS[] = {
0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000
};

// Ground tile (solid)
static const uint16_t TILE_GROUND_BITS[] = {
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF
};

// Wall tile
static const uint16_t TILE_WALL_BITS[] = {
0xFF00, 0xFF00, 0xFF00, 0xFF00,
0xFF00, 0xFF00, 0xFF00, 0xFF00
};

// Create tile sprites (8x8 tiles)
static const pixelroot32::graphics::Sprite TILES[] = {
{ TILE_EMPTY_BITS, 8, 8 }, // Index 0: Empty
{ TILE_GROUND_BITS, 8, 8 }, // Index 1: Ground
{ TILE_WALL_BITS, 8, 8 } // Index 2: Wall
{ TILE_GROUND_BITS, 8, 8 } // Index 1: Ground
};
```

#### 2bpp Tiles Example (Multi-color)
```cpp
#include <graphics/Renderer.h>

// 2bpp grass tile
static const uint8_t TILE_GRASS_DATA[] = {
0b01010101, 0b01010101, // Packed 2bpp data
// ...
};

static const Color GRASS_PALETTE[] = {
Color::Transparent, Color::DarkGreen, Color::Green, Color::LightGreen
};

static const pixelroot32::graphics::Sprite2bpp TILES_2BPP[] = {
{ TILE_GRASS_DATA, GRASS_PALETTE, 8, 8, 4 }
};
```

Expand Down Expand Up @@ -100,13 +108,15 @@ static pixelroot32::graphics::TileMap myTileMap = {

```cpp
void draw(pixelroot32::graphics::Renderer& renderer) override {
// Draw tilemap at position (0, 0)
// 1bpp Tilemap (requires a color)
renderer.drawTileMap(
myTileMap,
0, // x position
0, // y position
0, 0,
pixelroot32::graphics::Color::White
);

// 2bpp/4bpp Tilemap (colors are in the sprite palettes)
renderer.drawTileMap(myTileMap2bpp, 0, 100);
}
```

Expand Down
44 changes: 43 additions & 1 deletion docs/resources/available_tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,36 @@ This guide documents tools available to facilitate PixelRoot32 game development.

The Sprite Compiler converts PNG images to PixelRoot32 sprite data formats, making it easy to create sprites from image files.

### Installation
[Read more in the Sprite Compiler Guide](../tools/sprite_compiler/overview.md)

<!--
## Tilemap Editor

The Tilemap Editor is a visual tool for designing multi-layered tile-based environments. It allows you to import tilesets, paint maps, and export optimized C++ code directly for use with PixelRoot32.

[Read more in the Tilemap Editor Guide](../tools/tilemap_editor/overview.md)

### Key Features

- **Multi-layer editing**: Up to 8 layers with transparency support.
- **BPP support**: Export maps in 1bpp, 2bpp, or 4bpp formats.
- **Visual Tools**: Brush, Eraser, Rectangle Fill, and Pipette.
- **Standalone App**: Available as a portable `.exe` for Windows.

### Installation (Quick Start)

**From Source:**

```powershell
git clone https://github.com/Gperez88/PixelRoot32-Tilemap-Editor.git
cd PixelRoot32-Tilemap-Editor
pip install ttkbootstrap pillow jinja2
python main.py
```
-->

**From Source:**

```bash
git clone https://github.com/Gperez88/pr32-sprite-compiler.git
cd pr32-sprite-compiler
Expand All @@ -17,18 +44,21 @@ npm link # Optional: install globally
```

**As NPM Package:**

```bash
npm install -g pr32-sprite-compiler
```

### Basic Usage

**Command Line:**

```bash
pr32-sprite-compiler input.png output.h
```

**With Options:**

```bash
pr32-sprite-compiler input.png output.h --format 1bpp --name MY_SPRITE
```
Expand Down Expand Up @@ -69,16 +99,19 @@ static const pixelroot32::graphics::Sprite MY_SPRITE = {
### Advanced Options

**Batch Processing:**

```bash
pr32-sprite-compiler --batch sprites/*.png --output-dir sprites/out/
```

**Custom Palette:**

```bash
pr32-sprite-compiler input.png output.h --palette custom_palette.json
```

**Sprite Sheet:**

```bash
pr32-sprite-compiler sheet.png output.h --sheet 8x8 --count 16
```
Expand All @@ -97,11 +130,13 @@ If available, a GUI version provides visual feedback:
1. **Create or find a PNG image** (8x8, 16x16, etc.)

2. **Run the compiler:**

```bash
pr32-sprite-compiler player.png player_sprite.h --name PLAYER_SPRITE
```

3. **Include in your project:**

```cpp
#include "player_sprite.h"

Expand All @@ -113,15 +148,18 @@ If available, a GUI version provides visual feedback:
### Troubleshooting

**Image too large:**

- Sprites must be ≤ 16 pixels wide for 1bpp
- Reduce image size or split into multiple sprites

**Colors not converting correctly:**

- Ensure image uses indexed colors
- Use black/white for 1bpp
- Use 4 colors for 2bpp, 16 for 4bpp

**Output file not found:**

- Check write permissions
- Verify output path exists

Expand All @@ -132,6 +170,7 @@ If available, a GUI version provides visual feedback:
A tool to convert music files or MIDI to PixelRoot32 `MusicTrack` format.

**Planned Features:**

- MIDI to MusicTrack conversion
- Visual music editor
- Instrument preset management
Expand All @@ -142,6 +181,7 @@ A tool to convert music files or MIDI to PixelRoot32 `MusicTrack` format.
A tool to create tilemaps from image files or tile editors.

**Planned Features:**

- Image to tilemap conversion
- Tile editor integration
- Export to C++ arrays
Expand All @@ -158,12 +198,14 @@ A tool to create tilemaps from image files or tile editors.
### Workflow Integration

**Typical Workflow:**

1. Create/edit sprites in image editor
2. Compile sprites to C++ headers
3. Include headers in project
4. Use sprites in code

**Automation:**

```bash
# Build script example
#!/bin/bash
Expand Down
Loading
Loading