Tile based Sprite Sheets

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
Human Bolt Diary
Regular
Posts: 109
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Tile based Sprite Sheets

#1 Post by Human Bolt Diary » Fri Oct 11, 2013 1:52 am

TileSpriteSheet() is a class to split a large image (the sprite sheet) into a list of smaller images.
It requires every sprite to be the same size and spaced evenly on the sheet, making it limited to simple tile based sprite sheets.
At some point I may add support for sprites of different sizes and positions so that something like Texture Packer can be used.

If anyone reports bugs, I'll try to fix them ASAP.
If anyone has a suggestion to improve things (aside from differently sized sprites), I'll look into it.

How to use:

1) Drop the attached file into your project's main folder.
2) Call SpriteSheet().make and define your images based on what it returns

Basic Example:
$ my_sprite_sheet = SpriteSheet().make("sheet.png", (15,24),(3,1),(2,6))
image sprite1 = my_sprite_sheet[0]
image sprite2 = my_sprite_sheet[1]
image sprite3 = my_sprite_sheet[2]

label start:
show sprite1 at left
"Wowzers, Boss. Your image data's contained on a sprite sheet!"

In the example, we have a sprite sheet where each tile is 15x24. There are 3 columns and 1 row on the sheet. Each sprite is spaced with 2 pixels on the x axis, and 6 pixels on the y axis. The spacing argument is optional because ideally your sprite sheet would have no white space.

Functions:

TileSpriteSheet().make(file, sprite_x_y, sprite_amount, *spacing)

Crops file into a list of images.
It assumes every tile is the same size and spaced evenly apart.
Images are split top to bottom, left to right (By column, not row)

file = location of image file
sprite_x_y = tuple(x,y) of the individual sprite size
sprite_amount = tuple(x,y) of the number of sprites along the x and y axis
spacing = tuple(x,y) optional argument to define white space between each sprite

TileSpriteSheet().tint(sprites, tint_amount)
Takes a list of images (sprites) and tints them according to tint_amount

sprites = list of images to tint
tint_amount = tuple(r,g,b) of the amount to tint the sprites by.
Uses: http://www.renpy.org/wiki/renpy/doc/ref ... atrix.tint

TileSpriteSheet().darken(sprites)
Takes a list of images (sprites) and tints them to have a slightly darkened effect

TileSpriteSheet().silhouette(sprites)
Takes a list of images (sprites) and tints them to create a silhouette effect
Attachments
tilespritesheet.rpy
(1.79 KiB) Downloaded 183 times

Post Reply

Who is online

Users browsing this forum: No registered users