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

Author Topic: sprite lagging behind the cursor  (Read 2668 times)

0 Members and 1 Guest are viewing this topic.

mejak

  • Newbie
  • *
  • Posts: 8
    • View Profile
sprite lagging behind the cursor
« on: November 07, 2011, 10:34:39 pm »
I'm rather new to all this, and I'm not sure if this even qualifies as a problem, it's more of a question on how all this works, and if maybe I'm doing something wrong, so i pasted the whole code.

I created a sprite that replaces the cursor, and then set the position of the sprite to Mouse::GetPosition. But the sprite seems to be trailing behind the cursor, especially in fullscreen. Then i set the framelimit to 60 and it didn't help, but if I set it to 58 it still trails a little, but it's a lot better.

Oh I also commented out the 121 and 133 lines in WindowImpl before building the libs, I thought it might help(it didn't).

I'm using SFML2, winxp

any help or info would be appreciated.

Code: [Select]


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

int main()
{
sf::VideoMode VMode(1280, 960, 32);
sf::RenderWindow Window(VMode, "SFML Sample Application", sf::Style::Default, sf::ContextSettings());

sf::View View;
View.Reset(sf::FloatRect(0, 0, 320, 240));

Window.SetView(View);
Window.SetFramerateLimit(60);
//Window.ShowMouseCursor(false);

sf::Mouse Mouse;

sf::Texture CursorTexture;
CursorTexture.LoadFromFile("Cursor.png");

sf::Sprite CursorSprite;
CursorSprite.SetTexture(CursorTexture);
CursorSprite.SetSubRect(sf::IntRect(0, 0, 9, 9));
CursorSprite.SetPosition(0.0f, 0.0f);


        while (Window.IsOpened())
        {
                sf::Event Event;            

while (Window.PollEvent(Event))
{
if (Event.Type == sf::Event::Closed)
Window.Close();

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
Window.Close();

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Return))
{
Window.Create(VMode, "SFML Sample Application", sf::Style::Fullscreen);
Window.SetView(View);
Window.SetFramerateLimit(60);
//Window.ShowMouseCursor(false);
}
}
CursorSprite.SetPosition((sf::Mouse::GetPosition(Window).x /4) - 4, (sf::Mouse::GetPosition(Window).y /4) - 4);

                Window.Clear(sf::Color(25, 25, 25));
Window.Draw(CursorSprite);
Window.Display();
        }

        return 0;
}


Haikarainen

  • Guest
sprite lagging behind the cursor
« Reply #1 on: November 08, 2011, 05:52:58 pm »
What happens if you disable frameratelimit and enable vsync instead? Or put both disabled?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
sprite lagging behind the cursor
« Reply #2 on: November 08, 2011, 07:18:34 pm »
I would say rather the problem is that the mouse is hardware accelerated so when you place the sprite at the same position as where the mouse was, the mouse is already long gone from that point.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

mejak

  • Newbie
  • *
  • Posts: 8
    • View Profile
sprite lagging behind the cursor
« Reply #3 on: November 09, 2011, 04:20:51 am »
yeah, i guess it had to do with the mouse drivers, on my laptop it's working fine. I have a logitech G500, and I played around with the settings in setpoint, turned off the acceleration, but it didn't help. thanks, at least now i know it's not my code.

 

anything