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

Author Topic: Why is it necessary to call setView every tick?  (Read 2865 times)

0 Members and 1 Guest are viewing this topic.

JunkerKun

  • Newbie
  • *
  • Posts: 35
    • View Profile
Why is it necessary to call setView every tick?
« on: December 07, 2012, 06:54:11 pm »
So, I tried to use view to have it to follow player:
void Player::Step() {
        /*if (CollisionPoint(viewXview+Mouse.getPosition(window).x,viewYview+Mouse.getPosition(window).y,ObjMan.GetObject(id))) {
                sprite.setColor(sf::Color(sf::Color::Red));
        } else sprite.setColor(sf::Color(sf::Color::White));*/

        if (Keyboard.isKeyPressed(sf::Keyboard::Key::Right)) {
        speed=2;
        animXdir=1;
        };
        if (Keyboard.isKeyPressed(sf::Keyboard::Key::Left)) {
        speed=-2;
        animXdir=-1;
        };
        if (!Keyboard.isKeyPressed(sf::Keyboard::Key::Right) &&
                !Keyboard.isKeyPressed(sf::Keyboard::Key::Left)) {
        speed=0;
        };
        x+=speed;
        viewXview=x;
        viewYview=y;
        view.setCenter(viewXview,viewYview);
        viewXview-=320;
        viewYview-=240;
        Update();
};
And after a while I noticed that it is slitly shifted to the side when player is moving. And it was fixed only after I made it to call setView every tick (in main cycle, before all rendering). Is there a reason for that or am I just being dumb?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Why is it necessary to call setView every tick?
« Reply #1 on: December 07, 2012, 07:02:49 pm »
Yes the view is pass by value and not by reference, thus it will only change if you call setView. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

JunkerKun

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Why is it necessary to call setView every tick?
« Reply #2 on: December 07, 2012, 07:09:56 pm »
Yes the view is pass by value and not by reference, thus it will only change if you call setView. ;)
Oh. So in other words it needs to be updated manualy?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Why is it necessary to call setView every tick?
« Reply #3 on: December 07, 2012, 07:16:41 pm »
Oh. So in other words it needs to be updated manualy?
Yes. This has the advantage that the sf::View has no restrictions with respect to lifetime. You can pass temporary objects to setView(), for example.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

JunkerKun

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Why is it necessary to call setView every tick?
« Reply #4 on: December 07, 2012, 07:28:05 pm »
Okay, thanks for help!

 

anything