Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion coresdk/src/coresdk/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ namespace splashkit_lib
return point_at(_camera_x + screen_width() / 2.0f, _camera_y + screen_height() / 2.0f);
}


void reset_camera()
{
_camera_x = 0;
_camera_y = 0;
}

//---------------------------------------------------------------------------
// World-To-Screen Translation
Expand Down
7 changes: 7 additions & 0 deletions coresdk/src/coresdk/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ namespace splashkit_lib
*/
point_2d screen_center();

/**
* Reset the camera position back to (x = 0, y = 0).
*
* This is the equivilent to calling the functions set_camera_x(0) and set_camera_y(0).
*/
void reset_camera();

//---------------------------------------------------------------------------
// World-To-Screen Translation
//---------------------------------------------------------------------------
Expand Down
12 changes: 10 additions & 2 deletions coresdk/src/test/test_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2016 Andrew Cain. All rights reserved.
//

#include <cassert>
#include "window_manager.h"
#include "sprites.h"
#include "graphics.h"
Expand Down Expand Up @@ -52,8 +53,10 @@ void run_camera_test()
}
else
{
set_camera_x(0);
set_camera_y(0);
reset_camera();

assert(camera_x() == 0);
assert(camera_y() == 0);
}

clear_screen(COLOR_WHITE);
Expand All @@ -69,5 +72,10 @@ void run_camera_test()
refresh_screen();
}

reset_camera();

assert(camera_x() == 0);
assert(camera_y() == 0);

close_window(w1);
}