diff --git a/src/sprite.odin b/src/sprite.odin index 59ef46f..c3b0afd 100644 --- a/src/sprite.odin +++ b/src/sprite.odin @@ -48,40 +48,24 @@ draw_sprite_frame :: proc( widthf := f32(sprite.width) heightf := f32(sprite.height) - src_width := widthf - src_height := heightf - src_x := frame_pos.x * widthf - src_y := frame_pos.y * heightf - - if flipX { - src_width = -src_width - src_x += widthf - } - - if flipY { - src_height = -src_height - src_y += heightf - } - source_rect := raylib.Rectangle { - x = src_x, - y = src_y, - width = src_width, - height = src_height, - } - - dest_rect := raylib.Rectangle { - x = draw_pos.x, - y = draw_pos.y, + x = frame_pos.x * widthf, + y = frame_pos.y * heightf, width = widthf, height = heightf, } - // origin := raylib.Vector2{widthf * 0.5, heightf * 0.5} - // dest_rect.x = draw_pos.x + widthf * 0.5 - // dest_rect.y = draw_pos.y + heightf * 0.5 + if flipX do source_rect.width *= -1 + if flipY do source_rect.height *= -1 - origin := raylib.Vector2{0, 0} + origin := raylib.Vector2{widthf / 2, heightf / 2} + + dest_rect := raylib.Rectangle { + x = draw_pos.x + origin.x, + y = draw_pos.y + origin.y, + width = widthf, + height = heightf, + } raylib.DrawTexturePro(sprite.texture, source_rect, dest_rect, origin, 0.0, color) }