Tutorial | Sdl3

// Sprite animation properties #define SPRITE_SIZE 64 #define FRAME_COUNT 4 #define ANIMATION_SPEED 8 // Frames per animation step

printf("Controls: WASD or Arrow Keys to move\n"); printf("Press ESC to quit\n"); sdl3 tutorial

// Create window SDL_Window* window = SDL_CreateWindow("SDL3 Sprite Animation Tutorial", SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_RESIZABLE); if (!window) printf("Window creation failed: %s\n", SDL_GetError()); SDL_Quit(); return 1; printf("Press ESC to quit\n")

for (int i = 0; i < FRAME_COUNT; i++) sprite->frames[i].x = i * frame_width; sprite->frames[i].y = 0; sprite->frames[i].w = frame_width; sprite->frames[i].h = frame_height; if (!window) printf("Window creation failed: %s\n"

else // Reset to first frame when idle sprite->current_frame = 0; sprite->frame_counter = 0;

// Boundary checking if (sprite->x < 0) sprite->x = 0; if (sprite->x > SCREEN_WIDTH - SPRITE_SIZE) sprite->x = SCREEN_WIDTH - SPRITE_SIZE; if (sprite->y < 0) sprite->y = 0; if (sprite->y > SCREEN_HEIGHT - SPRITE_SIZE) sprite->y = SCREEN_HEIGHT - SPRITE_SIZE;

// Clean up resources void destroy_animated_sprite(AnimatedSprite* sprite) if (sprite) if (sprite->texture) SDL_DestroyTexture(sprite->texture); free(sprite);