OldSchool Library
Simili sprite system

Functions

void oslSetImageFrame (OSL_IMAGE *img, int frame)
 

Detailed Description

A basic system allowing you to cut your images just as if they were sprites. Remember that the maximum size of an image is 512x512!

Function Documentation

◆ oslSetImageFrame()

void oslSetImageFrame ( OSL_IMAGE * img,
int frame )
extern

Sets the current frame of an image for sprite-based rendering.

This function prepares the image to display a specific frame from a sprite sheet. A sprite sheet is an image where multiple sprites (small images) are arranged in a grid. This function is used to select the sprite frame that you want to draw.

@param img
    Pointer to the image to set the frame for.
@param frame
    The index of the frame to be displayed. Frames are indexed starting from 0.

\b Example:
\code
// Draws a specific frame of an image
void DrawImageFrame(OSL_IMAGE *img, int frame) {
    oslSetImageFrame(img, frame);
    oslDrawImage(img);
}

// Alternative method using a macro
#define DrawImageFrame(img, frame) ({ oslSetImageFrame(img, frame); oslDrawImage(img); })

// Inline function for specific frame drawing
extern inline void DrawImageFrame(OSL_IMAGE *img, int frame) {
    oslSetImageFrame(img, frame);
    oslDrawImage(img);
}

// Draws a specific frame of an image at a specified location
void DrawImageFrameXY(OSL_IMAGE *img, int x, int y, int frame) {
    oslSetImageFrame(img, frame);
    oslDrawImageXY(img, x, y);
}

// Load an image with specified frame size
OSL_IMAGE *LoadSpriteFilePNG(char *filename, int location, int pixelFormat, int frameWidth, int frameHeight) {
    OSL_IMAGE *img = oslLoadImageFile(filename, location, pixelFormat);
    if (img)
            oslSetImageFrameSize(img, frameWidth, frameHeight);
    return img;
}

void main() {
    // Initialization
    [...]

    // 30x40 pixels per sprite
    OSL_IMAGE *myImage;
    myImage = LoadSpriteFilePNG("test.png", OSL_IN_RAM, OSL_PF_5551, 30, 40);
    [...]

    // Draw the frame n°2 (that is, the third sprite) at location (0, 0)
    DrawImageFrameXY(myImage, 0, 0, 2);
    [...]
}
\endcode