diff options
| author | iamcheeseman <[hidden email]> | 2026-01-12 20:51:28 -0500 |
|---|---|---|
| committer | iamcheeseman <[hidden email]> | 2026-01-12 20:51:28 -0500 |
| commit | 7fb83578b99aa224f7545f4118a46e84b58a9295 (patch) | |
| tree | 515e294ac7de167c4501cc0a8d375b13213faf36 /src/draw | |
| parent | 2b3a3ea9f4bc902b1b357fd149952d4570b25bf3 (diff) | |
NEW ASSET SYSTEM WOOOOOOOOHOOOOOOOOOOOOOOOOOOOOOOOOO
Diffstat (limited to 'src/draw')
| -rw-r--r-- | src/draw/sprite.odin | 94 |
1 files changed, 0 insertions, 94 deletions
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, - ) -} |
