1
System / [SFML 2.0 RC] Mouse and moving sprite
« on: May 21, 2012, 08:46:32 pm »
Hey, I have a strange problem. When I am moving a cursor on the sfml window and try move a sprite it is moving faster than when i am not moving a cursor. When cursor isnt in window area, sprite is moving slower too. I thought that is something wrong with my code, but I have made a test in clear project and I have still this problem.
Somebody know what is it or could check it on his computer?
Sprite isnt drawing correctly, I saw two small rectangles, but i should see one big. In main project I dont have this problem (probably it is fault my integrated graphics card).
Thank you for sharing with me your time.
Somebody know what is it or could check it on his computer?
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::Texture tex;
tex.create(10,30);
sf::Sprite sprite;
sprite.setColor(sf::Color::Green);
sprite.setTexture(tex);
sprite.setPosition(200,100);
while (window.isOpen())
{
sf::Event Event;
while (window.pollEvent(Event))
{
if (Event.type == sf::Event::Closed)
window.close();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
sprite.move(-10,0);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
sprite.move(10,0);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
sprite.move(0,-10);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
sprite.move(0,10);
}
window.clear(sf::Color::White);
window.draw(sprite);
window.display();
}
return EXIT_SUCCESS;
}
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::Texture tex;
tex.create(10,30);
sf::Sprite sprite;
sprite.setColor(sf::Color::Green);
sprite.setTexture(tex);
sprite.setPosition(200,100);
while (window.isOpen())
{
sf::Event Event;
while (window.pollEvent(Event))
{
if (Event.type == sf::Event::Closed)
window.close();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
sprite.move(-10,0);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
sprite.move(10,0);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
sprite.move(0,-10);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
sprite.move(0,10);
}
window.clear(sf::Color::White);
window.draw(sprite);
window.display();
}
return EXIT_SUCCESS;
}
Sprite isnt drawing correctly, I saw two small rectangles, but i should see one big. In main project I dont have this problem (probably it is fault my integrated graphics card).
Thank you for sharing with me your time.