Nimbin[12]?SDL & Graphics / mapcreator / commits / 573a8e2

mapcreator git · master

SDL3 2.5D game and engine using assets, with map editor

sdl3 c++ game engine map-editor cmake · first commit 2025-10-31 · last commit 2026-09-07 (1 month ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-spieleentwicklung/map_creator

C++ 99.3%
git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gz

Reduce jittering maybe a bit while moving diagonally

Christian Immanuel · 2026-02-12 10:48 · 573a8e2610ab2779750423e74fec8e759b761c11

 src/character/character.cpp |  4 ++--
 src/character/enemy.cpp     |  4 ++--
 src/game/state_playing.cpp  | 20 ++++++++++++++++----
 src/objects/object.cpp      |  4 ++--
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/character/character.cpp b/src/character/character.cpp
index 9a134f4..c3e4287 100644
--- a/src/character/character.cpp
+++ b/src/character/character.cpp
@@ -222,8 +222,8 @@ Character::Draw(SDL_Renderer* renderer) {
 
     for (const auto& t : tiles_in_reach) {
         SDL_FRect tile_rect = {
-            Scale(static_cast<int>(t.x * Tile::tile_size) + Map::offset.x),
-            Scale(static_cast<int>(t.y * Tile::tile_size) + Map::offset.y),
+            Scale(t.x * Tile::tile_size) + Map::offset.x,
+            Scale(t.y * Tile::tile_size) + Map::offset.y,
             Scale(Tile::tile_size),
             Scale(Tile::tile_size)
         };
diff --git a/src/character/enemy.cpp b/src/character/enemy.cpp
index 0d70777..17e0df6 100644
--- a/src/character/enemy.cpp
+++ b/src/character/enemy.cpp
@@ -198,8 +198,8 @@ Enemy::Draw(SDL_Renderer* renderer) {
 
     for (const auto& t : tiles_in_reach) {
         SDL_FRect tile_rect = {
-            Scale(static_cast<int>(t.x * Tile::tile_size) + Map::offset.x),
-            Scale(static_cast<int>(t.y * Tile::tile_size) + Map::offset.y),
+            Scale(t.x * Tile::tile_size) + Map::offset.x,
+            Scale(t.y * Tile::tile_size) + Map::offset.y,
             Scale(Tile::tile_size),
             Scale(Tile::tile_size)
         };
diff --git a/src/game/state_playing.cpp b/src/game/state_playing.cpp
index c991c1b..fa27642 100644
--- a/src/game/state_playing.cpp
+++ b/src/game/state_playing.cpp
@@ -191,19 +191,31 @@ void update_CameraOffset(
     const float player_screen_x = player_world.x + Map::offset.x;
     const float player_screen_y = player_world.y + Map::offset.y;
 
+    float target_offset_x = Map::offset.x;
+    float target_offset_y = Map::offset.y;
+
+    // Horizontal deadzone
     if (player_screen_x < margin_x) {
-        Map::offset.x = margin_x - player_world.x;
+        target_offset_x = margin_x - player_world.x;
     }
     else if (player_screen_x > logical_w - margin_x) {
-        Map::offset.x = (logical_w - margin_x) - player_world.x;
+        target_offset_x = (logical_w - margin_x) - player_world.x;
     }
 
+    // Vertical deadzone
     if (player_screen_y < margin_y) {
-        Map::offset.y = margin_y - player_world.y;
+        target_offset_y = margin_y - player_world.y;
     }
     else if (player_screen_y > logical_h - margin_y) {
-        Map::offset.y = (logical_h - margin_y) - player_world.y;
+        target_offset_y = (logical_h - margin_y) - player_world.y;
     }
+
+    // --- Smooth interpolation ---
+    const float follow_speed = 10.0f; // higher = snappier
+    const float t = 1.0f - std::exp(-follow_speed * Default::delta_time);
+
+    Map::offset.x += (target_offset_x - Map::offset.x) * t;
+    Map::offset.y += (target_offset_y - Map::offset.y) * t;
 }
 
 void StatePlaying::Update(Game* game) {
diff --git a/src/objects/object.cpp b/src/objects/object.cpp
index a0781e7..2e15682 100644
--- a/src/objects/object.cpp
+++ b/src/objects/object.cpp
@@ -286,8 +286,8 @@ Object::Draw(SDL_Renderer* renderer, SDL_FPoint position, bool is_transparent, i
 
             if (collision_map[index]) {
                 SDL_FRect col_rect = {
-                    Scale(static_cast<float>(position.x + static_cast<int>(x * Tile::tile_collider_size)) + Map::offset.x),
-                    Scale(static_cast<float>(position.y + static_cast<int>(y * Tile::tile_collider_size)) + Map::offset.y),
+                    Scale(static_cast<float>(position.x + (x * Tile::tile_collider_size)) + Map::offset.x),
+                    Scale(static_cast<float>(position.y + (y * Tile::tile_collider_size)) + Map::offset.y),
                     Scale(static_cast<float>(Tile::tile_collider_size)),
                     Scale(static_cast<float>(Tile::tile_collider_size))
                 };