Skip to content
Martin Cohen edited this page Dec 1, 2016 · 2 revisions

Punity minimizes number of built-in asset types to Bitmap, Font and Sound and even this might shrink down in the future. The actual image and audio files are stored in ./res directory and are embedded to the EXE file at compile time using definition in RC file (typically main.rc). An RC file looks like this:

icon.ico ICON "res\\icon.ico"
font.png RESOURCE "res\\font.png"
image.png RESOURCE "res\\image.png"
explosion.ogg RESOURCE "res\\explosion.ogg"

The format is specified by Microsoft, but luckily for our need it's quite straight-forward <Name> RESOURCE <Path> (You only use ICON for the first .ico file). The <Name> is a string that you'll use in Punity, so in the code you can load the image.png like this:

Bitmap bitmap;
bitmap_load_resource(&bitmap, "image.png", 0);

Bitmaps

Please note that Punity requires lib/stb_image.h in order to load any reasonable image types (PNG, JPG, GIF (single-frame)). Punity includes this file automatically if PUN_USE_STB_IMAGE is set to 1 (default).

It is important to note that Punity is 8-bit, and uses indexed color table (or palette) of total of 255 colors (with 0 being reserved for transparency). Every image is loaded as 32-bit RGBA, then for each new color a new entry in CORE->palette is added. If you use up all your colors, Punity will fail with error. So be sure that you use as little different colors as possible.

Sounds

Please note that Punity requires lib/stb_vorbis.c to load OGG files (no other formats are supported). Punity includes this file automatically if PUN_USE_STB_VORBIS is set to 1 (default).

Sounds are automatically resampled during the playback to the current sample rate (though Punity tries to set it to 48kHz). Also, sounds are always decoded to raw samples when loaded with sound_load_resource, so long audio files might need a lot of memory in CORE->storage (see Memory).

Clone this wiki locally