diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-12-19 20:23:29 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-12-19 20:23:29 +0100 |
commit | fab23ff0b70f338fcaeadf11d3855e705e0be6be (patch) | |
tree | 4e447478a203f498c0962c311071a281bb6a72f7 | |
parent | 7d0b6babe9906df0990028e41e0f895fab605498 (diff) |
Smooth camera following.
-rw-r--r-- | src/game/interface.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/game/interface.cpp b/src/game/interface.cpp index 41e2365..0ffdbab 100644 --- a/src/game/interface.cpp +++ b/src/game/interface.cpp @@ -39,6 +39,15 @@ void state_t::tick(double dt) view_size.y = view_scale * size.y / size.x; } + if (game->selected_units.size() && camera.following) { + for (entity_t *ent : game->selected_units) + follow_center += ent->render_bounds.center(); + follow_center /= game->selected_units.size(); + + camera.follow_center[0] = expfade(camera.follow_center[0], follow_center[0], dt, 25); + camera.follow_center[1] = expfade(camera.follow_center[1], follow_center[1], dt, 25); + } + view_center = camera.center; if (camera.following) @@ -156,17 +165,6 @@ void state_t::tick(double dt) } } - if (game->selected_units.size() && camera.following) { - for (entity_t *ent : game->selected_units) - follow_center += ent->render_bounds.center(); - follow_center /= game->selected_units.size(); - - - camera.follow_center = follow_center; - //camera.follow_center[0] = expfade(camera.follow_center[0], follow_center[0], dt, 5); - //camera.follow_center[1] = expfade(camera.follow_center[1], follow_center[1], dt, 5); - } - // Compute this _after_ the setView above. wmouse = window->mapPixelToCoords(sf::Mouse::getPosition(*window)); |