From f46c66485b758385417431d290e1a2958dececea Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 6 Sep 2025 10:50:07 -0700 Subject: Implement camera clipping for ortho maps --- include/isogfx/gfx2d.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/isogfx/gfx2d.h b/include/isogfx/gfx2d.h index a3ddbb6..33a4591 100644 --- a/include/isogfx/gfx2d.h +++ b/include/isogfx/gfx2d.h @@ -110,15 +110,8 @@ void gfx2d_set_sprite_animation(Gfx2d*, Sprite, int animation); /// Currently, this updates the sprite animations. void gfx2d_update(Gfx2d*, double t); -// TODO: Do we really need to store the camera in the library? It's not used -// for anything other than to render, so we could remove library state and -// take a camera argument in render() instead. - -/// Set the camera. -void gfx2d_set_camera(Gfx2d*, int x, int y); - /// Render the world. -void gfx2d_render(Gfx2d*); +void gfx2d_render(Gfx2d*, int camera_x, int camera_y); /// Draw/overlay a tile at position (x,y). /// @@ -127,6 +120,16 @@ void gfx2d_render(Gfx2d*); /// position (x,y) instead, use gfx2d_set_tile(). void gfx2d_draw_tile(Gfx2d*, int x, int y, Tile); +/// Clip camera coordinates to the loaded map. +/// +/// This is useful for implementing camera movement, in which you typically +/// want the camera to stay within the map's bounds. +/// +/// (x,y) are the top-left coordinates of the camera. +/// +/// A map must have previously been loaded. +void gfx2d_clip_camera(const Gfx2d*, float* x, float* y); + /// Get the virtual screen's dimensions. void gfx2d_get_screen_size(const Gfx2d*, int* width, int* height); -- cgit v1.2.3