Raylib Recitals: Custom Cursor

Raylib is a C language game programming library that's designed to be easy to use, so you can concentrate on prototyping and having fun. Modelled after my PICO-8 examples I'm starting a new set of articles called "Raylib Recitals" designed to be simple single file examples of how to get stuff done in RayLib. Here's a simple way to implement a custom mouse cursor using a Sprite.

#include "raylib.h"

typedef struct Sprite {
    Texture2D texture;
    Rectangle rect;
    Vector2 position;
} Sprite;

int main() {
    InitWindow(800, 600, "Cursor Test");
    SetTargetFPS(60);

    Sprite cursor = (Sprite) {
        .texture = LoadTexture("resources/pointer.png"),
        .position = {0.0f, 0.0f},
        .rect = {0.0f, 0.0f, 64.0f, 64.0f},
    };

    HideCursor();
    while (!WindowShouldClose())
    {
        cursor.position = (Vector2){ .x = GetMousePosition().x, .y = GetMousePosition().y };
        BeginDrawing();
        ClearBackground(BLACK);
        DrawTextureRec(cursor.texture,cursor.rect,cursor.position,WHITE);
        EndDrawing();
    }

    UnloadTexture(cursor.texture);
    CloseWindow();

    return 0;
}