diff options
| author | Xander Swan <email> | 2025-12-03 09:52:13 -0500 |
|---|---|---|
| committer | Xander Swan <email> | 2025-12-03 09:52:13 -0500 |
| commit | 53cba1d004451f0782312cb203afb7da47a29c5f (patch) | |
| tree | b772324597c52674a626c7137359d34f528b1bd2 /src/draw/sprite.odin | |
| parent | bb52b5f9c9def80b1e8704acabde6f8c6a34e1a2 (diff) | |
update renderer structure a lil
Diffstat (limited to 'src/draw/sprite.odin')
| -rw-r--r-- | src/draw/sprite.odin | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/draw/sprite.odin b/src/draw/sprite.odin index e2f2639..ff8ce58 100644 --- a/src/draw/sprite.odin +++ b/src/draw/sprite.odin @@ -1,10 +1,12 @@ package draw import "core:log" +import "core:math" import "core:image" import "core:image/qoi" import sg "shared:sokol/gfx" +import stime "shared:sokol/time" Sprite :: struct { image: sg.Image, @@ -12,6 +14,13 @@ Sprite :: struct { active_anim: u32, frame_time: f32, current_frame: i32, + + width: i32, + height: i32, + + pos: Vec2, + offset: Vec2, + scale: Vec2, } init_sprite :: proc( @@ -37,7 +46,17 @@ init_sprite :: proc( }) sprite.anim = anim - log.debugf("loaded sprite '%v'", path) + sprite.width = i32(img.width / len(sprite.anim.frames)) + sprite.height = i32(img.height) + + sprite.scale = Vec2{1, 1} + + log.debugf( + "loaded sprite '%v' %vx%v (%vx%v)", + path, + sprite.width, sprite.height, + img.width, img.height, + ) return true } @@ -69,9 +88,6 @@ update_sprite :: proc(sprite: ^Sprite, dt: f32) { draw_sprite :: proc( r: ^Renderer, sprite: Sprite, - pos: Vec2, - offset := Vec2{0, 0}, - scale := Vec2{1, 1}, ) { frame := sprite.anim.frames[sprite.current_frame] @@ -82,8 +98,8 @@ draw_sprite :: proc( Vec2{f32(frame.rect.x), f32(frame.rect.y)}, Vec2{f32(frame.rect.w), f32(frame.rect.h)}, }, - pos, - offset, - scale, + sprite.pos, + sprite.offset, + sprite.scale, ) } |
