So I have been messing around with sf::View recently (SFML 1.6) and made the simple program below:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600), "Sprite Test");
sf::Image ForestTileImg;
sf::Image PlayerImg;
if(!ForestTileImg.LoadFromFile("forest_terrain_tile.png")) {
return EXIT_FAILURE;
}
if(!PlayerImg.LoadFromFile("player.png")) {
return EXIT_FAILURE;
}
ForestTileImg.SetSmooth(false);
PlayerImg.SetSmooth(false);
sf::Sprite PlayerObj(PlayerImg);
sf::Sprite ForestTileObj(ForestTileImg);
ForestTileObj.SetPosition(400,300);
PlayerObj.SetPosition(400, 300);
float NewX = 400;
float NewY = 300;
sf::Vector2f Center(800, 600);
sf::Vector2f HalfSize(400, 300);
sf::View View(Center, HalfSize);
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
if (App.GetInput().IsMouseButtonDown(sf::Mouse::Left))
{
NewX = App.GetInput().GetMouseX();
NewY = App.GetInput().GetMouseY();
}
PlayerObj.SetPosition(NewX, NewY);
View.SetCenter(NewX, NewY);
App.SetView(View);
App.Clear();
App.Draw(ForestTileObj);
App.Draw(PlayerObj);
App.Display();
}
return EXIT_SUCCESS;
}
The view stays on the play well, however, the player cannot move outside of the initial area that was first viewed. To say that another way, the player cant move outside of the initial 800, 600 window area. Suggestions?