#include "../include/animated_texture.h" #include AnimatedTexture animated_texture_create( const char *file_path, int number_of_frames, float speed ) { Texture2D texture = LoadTexture(file_path); Rectangle current_frame = { 0, 0, texture.width / (float)number_of_frames, texture.height }; return (AnimatedTexture){ .number_of_frames = number_of_frames, .current_frame = current_frame, .duration_left = 1.0f, .speed = speed, .texture = texture }; } int animated_texture_delete(AnimatedTexture animated_texture) { UnloadTexture(animated_texture.texture); return EXIT_SUCCESS; } void animated_texture_update(AnimatedTexture *animated_texture) { float delta_time = GetFrameTime(); animated_texture->duration_left -= delta_time * animated_texture->speed; if (animated_texture->duration_left > 0.0) return; animated_texture->duration_left = 1.0f; Rectangle next_frame = { ((int)animated_texture->current_frame.x + (int)animated_texture->current_frame.width) % animated_texture->texture.width, 0, animated_texture->current_frame.width, animated_texture->current_frame.height }; animated_texture->current_frame = next_frame; } void animated_texture_draw( AnimatedTexture *animated_texture, Vector2 position, Color tint ) { Rectangle dest = { position.x, position.y, animated_texture->current_frame.width, animated_texture->current_frame.height }; DrawTexturePro( animated_texture->texture, animated_texture->current_frame, dest, (Vector2){ 0, 0 }, 0.0f, tint ); }