aboutsummaryrefslogtreecommitdiff
path: root/src/draw/sprite.odin
diff options
context:
space:
mode:
authorXander Swan <no email>2025-12-17 18:38:21 -0500
committerXander Swan <no email>2025-12-17 18:38:21 -0500
commitce4d64bd41937d7dff18ca607122188dc338d696 (patch)
treead5f7cbdffcc1478883cbca0ea7b8365b2108d0a /src/draw/sprite.odin
parent87a7a010ecbe2cb99fedf44d0cac31e2efae86d5 (diff)
switch to raylib, update some structure
Diffstat (limited to 'src/draw/sprite.odin')
-rw-r--r--src/draw/sprite.odin44
1 files changed, 19 insertions, 25 deletions
diff --git a/src/draw/sprite.odin b/src/draw/sprite.odin
index 59d1c32..a6a109b 100644
--- a/src/draw/sprite.odin
+++ b/src/draw/sprite.odin
@@ -1,13 +1,14 @@
package draw
import "core:log"
-import "core:image"
-import "core:image/qoi"
+// import "core:image"
+import "core:mem"
+// import "core:image/qoi"
-import sg "shared:sokol/gfx"
+import rl "vendor:raylib"
Sprite :: struct {
- image: sg.Image,
+ image: rl.Texture2D,
anim: Animation,
active_anim: u32,
frame_time: f32,
@@ -18,6 +19,7 @@ Sprite :: struct {
pos: Vec2,
offset: Vec2,
+ rotation: f32,
scale: Vec2,
}
@@ -26,26 +28,15 @@ init_sprite :: proc(
path: string,
anim: Animation = {},
) -> bool {
- img, img_err := qoi.load_from_file(path)
- if img_err != nil {
- log.error("could not load image")
- return false
- }
- defer image.destroy(img)
+ byte_path := make([]u8, len(path) + 1, context.temp_allocator)
+ copy(byte_path, path)
+ byte_path[len(path)] = 0
- sprite.image = sg.make_image({
- width = i32(img.width),
- height = i32(img.height),
- data = {
- mip_levels = {
- 0 = {ptr=&img.pixels.buf[0], size=len(img.pixels.buf)},
- },
- },
- })
+ sprite.image = rl.LoadTexture(transmute(cstring)&byte_path[0])
sprite.anim = anim
- sprite.width = i32(img.width / len(sprite.anim.frames))
- sprite.height = i32(img.height)
+ sprite.width = i32(int(sprite.image.width) / len(sprite.anim.frames))
+ sprite.height = i32(sprite.image.height)
sprite.scale = Vec2{1, 1}
@@ -53,12 +44,16 @@ init_sprite :: proc(
"loaded sprite '%v' %vx%v (%vx%v)",
path,
sprite.width, sprite.height,
- img.width, img.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]
}
@@ -84,13 +79,11 @@ update_sprite :: proc(sprite: ^Sprite, dt: f32) {
}
sprite :: proc(
- r: ^Renderer,
sprite: Sprite,
) {
frame := sprite.anim.frames[sprite.current_frame]
- texture(
- r,
+ texture_quad(
sprite.image,
Rect {
Vec2{f32(frame.rect.x), f32(frame.rect.y)},
@@ -98,6 +91,7 @@ sprite :: proc(
},
sprite.pos,
sprite.offset,
+ sprite.rotation,
sprite.scale,
)
}