Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to stop scrolling when player reach end of the map  (Read 1454 times)

0 Members and 1 Guest are viewing this topic.

newbie123

  • Newbie
  • *
  • Posts: 27
    • View Profile
How to stop scrolling when player reach end of the map
« on: December 23, 2011, 08:06:08 am »
Hello
as the title say how can i stop scrolling when i reach a certain position?

Code: [Select]


#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Views");

    sf::Image BackgroundImage;
    if (!BackgroundImage.LoadFromFile("background.png"))
        return EXIT_FAILURE;

    sf::Sprite Background1(BackgroundImage);
Background1.SetPosition(0, 0);

sf::Sprite Background2(BackgroundImage);
Background2.SetPosition(500, 0);

sf::Sprite Background3(BackgroundImage);
Background3.SetPosition(0, 500);

sf::Sprite Background4(BackgroundImage);
Background4.SetPosition(500, 500);


    sf::Vector2f Center(500, 500);
    sf::Vector2f HalfSize(400, 300);
    sf::View View(Center, HalfSize);


    while (App.IsOpened())
    {

        sf::Event Event;
        while (App.GetEvent(Event))
        {

        }


        float Offset = 200.f * App.GetFrameTime();
if(App.GetInput().GetMouseX() <=100) View.Move(-Offset, 0);
if(App.GetInput().GetMouseX() >=700) View.Move( Offset, 0);
if(App.GetInput().GetMouseY() <=100) View.Move( 0, -Offset);
if(App.GetInput().GetMouseY() >=500) View.Move( 0, Offset);



        App.SetView(View);

        App.Clear();

        App.Draw(Background1);
App.Draw(Background2);
App.Draw(Background3);
App.Draw(Background4);


        App.SetView(App.GetDefaultView());

        App.Display();
    }

    return 0;
}

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
How to stop scrolling when player reach end of the map
« Reply #1 on: December 23, 2011, 05:59:39 pm »
Like this:

Code: [Select]
if ((App.GetInput().GetMouseX() <=100) && (View.GetCenter().x >= 1000))   View.Move(-Offset, 0);

I've just limited the left end, you can replicate it for the others.