From 7fb83578b99aa224f7545f4118a46e84b58a9295 Mon Sep 17 00:00:00 2001 From: iamcheeseman <[hidden email]> Date: Mon, 12 Jan 2026 20:51:28 -0500 Subject: NEW ASSET SYSTEM WOOOOOOOOHOOOOOOOOOOOOOOOOOOOOOOOOO --- src/draw/sprite.odin | 94 ---------------------------------------------------- 1 file changed, 94 deletions(-) (limited to 'src/draw/sprite.odin') diff --git a/src/draw/sprite.odin b/src/draw/sprite.odin index ebe2e08..3a90dfe 100644 --- a/src/draw/sprite.odin +++ b/src/draw/sprite.odin @@ -4,97 +4,3 @@ import "core:log" import rl "vendor:raylib" -Sprite :: struct { - image: rl.Texture2D, - anim: Animation, - active_anim: u32, - frame_time: f32, - current_frame: i32, - - width: i32, - height: i32, - - pos: Vec2, - offset: Vec2, - rotation: f32, - scale: Vec2, - - just_finished_loop: bool, -} - -init_sprite :: proc( - sprite: ^Sprite, - path: string, - anim: Animation = {}, -) -> bool { - byte_path := make([]u8, len(path) + 1, context.temp_allocator) - copy(byte_path, path) - byte_path[len(path)] = 0 - - sprite.image = rl.LoadTexture(transmute(cstring)&byte_path[0]) - sprite.anim = anim - - sprite.width = i32(int(sprite.image.width) / len(sprite.anim.frames)) - sprite.height = i32(sprite.image.height) - - sprite.scale = Vec2{1, 1} - - log.debugf( - "loaded sprite '%v' %vx%v (%vx%v)", - path, - sprite.width, sprite.height, - sprite.image.width, sprite.image.height, - ) - - return true -} - -destroy_sprite :: proc(sprite: Sprite) { - rl.UnloadTexture(sprite.image) -} - -set_sprite_active_tag :: proc(sprite: ^Sprite, tag_name: string) { - sprite.active_anim = sprite.anim.frame_tags_indices[tag_name] -} - -update_sprite :: proc(sprite: ^Sprite, dt: f32) { - sprite.just_finished_loop = false - - sprite.frame_time += dt - - tag := sprite.anim.frame_tags[sprite.active_anim] - frame := sprite.anim.frames[sprite.current_frame] - duration := f32(frame.duration) / 1000 - - if sprite.frame_time > duration { - sprite.frame_time -= duration - sprite.current_frame += 1 - } - - if sprite.current_frame < tag.from { - sprite.current_frame = tag.to - sprite.just_finished_loop = true - } - if sprite.current_frame > tag.to { - sprite.current_frame = tag.from - sprite.just_finished_loop = true - } -} - -sprite :: proc( - sprite: Sprite, -) { - frame := sprite.anim.frames[sprite.current_frame] - - texture_quad( - sprite.image, - Rect { - Vec2{f32(frame.rect.x), f32(frame.rect.y)}, - Vec2{f32(frame.rect.w), f32(frame.rect.h)}, - }, - sprite.pos, - sprite.offset, - sprite.rotation, - sprite.scale, - ) -} -- cgit v1.3-2-g0d8e