Created
December 11, 2014 20:03
-
-
Save David-Mimnagh/86cbe27f61fc2075040f to your computer and use it in GitHub Desktop.
amount of code needed for the camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sf::RenderWindow& window = state_manager_.get_render_window(); | |
sf::View view_main; | |
view_main.setCenter(sf::Vector2f(player_.Shape().getOrigin().x, player_.Shape().getOrigin().y)); | |
view_main.setSize(sf::Vector2f(600, 400)); | |
view_main.move(player_.Shape().getPosition().x, player_.Shape().getPosition().y); | |
if (view_main.getCenter().x + (view_main.getSize().x / 2) >= LEVEL_WIDTH) | |
view_main.setCenter(LEVEL_WIDTH - (view_main.getSize().x / 2), view_main.getCenter().y); | |
if (view_main.getCenter().x - (view_main.getSize().x / 2) <= 0) | |
view_main.setCenter(0 + (view_main.getSize().x / 2) , view_main.getCenter().y); | |
if (view_main.getCenter().y + (view_main.getSize().y/2) >= LEVEL_HEIGHT) | |
view_main.setCenter(view_main.getCenter().x, LEVEL_HEIGHT - (view_main.getSize().y/2)); | |
if (view_main.getCenter().y - (view_main.getSize().y / 2) <= 0) | |
view_main.setCenter(view_main.getCenter().x, 0 + (view_main.getSize().y / 2)); | |
window.setView(view_main); // applying the view | |
window.draw(player_.Shape()); | |
// zoom the view relatively to its current size (apply a factor 0.5, so its final size is 600x400) | |
view_main.zoom(0.5f); | |
// define a centered viewport, with half the size of the window | |
view_main.setViewport(sf::FloatRect(0.25f, 0.25, 0.5f, 0.5f)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment