GBTile
The GBTile
class represents a single GameBoy tile (8x8 pixels, 16
Bytes).
Creating a tile from scratch:
from img2gb import GBTile
tile = GBTile()
tile.put_pixel(0, 0, 3) # Put a black pixel at (0, 0)
tile.data # -> [128, 128, 0, 0, 0, ...]
tile.to_hex_string() # -> "80 80 00 00 00 ..."
Creating a tile from a PIL image:
from img2gb import GBTile
from PIL import Image
image = Image.open("./my_tile.png")
tile = GBTile.from_image(image)
- class img2gb.gbtile.GBTile[source]
Stores and manipulates data of a single GameBoy tile (8x8 pixels).
- property data
Raw data of the tile.
- Type:
list of int
- classmethod from_image(pil_image, tile_x=0, tile_y=0, alternative_palette=False)[source]
Create a new GBTile from the given image.
- Parameters:
pil_image (PIL.Image.Image) – The input PIL (or Pillow) image.
tile_x (int) – The x location of the tile in the image (default =
0
).tile_y (int) – The y location of the tile in the image (default =
0
).alternative_palette (bool) – Use the sprite’s alternative palette (inverted colors, default =
False
).
- Return type:
- get_pixel(x, y)[source]
Returns the color id of a pixel of the tile.
- Parameters:
x (int) – The x coordinate of the pixel (0-7).
y (int) – The y coordinate of the pixel (0-7).
- Return type:
int
- put_pixel(x, y, color_id)[source]
Set the color of one of the tile’s pixels.
- Parameters:
x (int) – The x coordinate of the pixel to change (0-7).
y (int) – The y coordinate of the pixel to change (0-7).
color_id (int) – the color of the pixel (0-3).