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

Author Topic: Custom cursor has low fps  (Read 2693 times)

0 Members and 1 Guest are viewing this topic.

Tankists

  • Newbie
  • *
  • Posts: 3
    • View Profile
Custom cursor has low fps
« on: March 05, 2009, 04:11:05 pm »
I was searching this forum for a while but still didn't find answer to this question. I made simple program that has custom cursor(sprite moved to mouse position every frame) and when i move mouse it laggs(refreshes slowly). What am I doing wrong?

Code: [Select]

#include "SFML/Graphics.hpp"


int main(int charc, char* argv[])
{
    sf::RenderWindow screen(sf::VideoMode(800, 600, 32), "asd");
    sf::Event event;

    screen.SetFramerateLimit(60);
    screen.ShowMouseCursor(false);

    sf::Sprite cur;
    cur.SetScale(10.f, 10.f);
    cur.SetColor(sf::Color::Red);

    while (screen.IsOpened())
    {
        while (screen.GetEvent(event))
        {
            if (event.Type == sf::Event::Closed) screen.Close();
        }
        cur.SetPosition(screen.GetInput().GetMouseX(), screen.GetInput().GetMouseY() );

        screen.Clear(sf::Color::Black);

        screen.Draw(cur);

        screen.Display();
    }


    return 0;
}
Never die before you are done!

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Custom cursor has low fps
« Reply #1 on: March 26, 2009, 02:08:41 pm »
What happens when you to the same with the MouseMoved event?

Aval

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Custom cursor has low fps
« Reply #2 on: March 27, 2009, 01:33:08 am »
First of all, you set the maximum frame rate to be 60. It's not going to get faster than that. That won't make it refresh noticeably slowly, though. Under 20 fps is where it gets unacceptably slow.

Secondly, you don't assign an image or anything to the sprite. If you want just a plain colored square, perhaps you should use sf::Shape. I haven't seen this used before like what you are doing with the sprite, but maybe it works.

Also, you might want to use sf::Input for getting input. It's often easier, especially for key presses and mouse location.