16
Graphics / Key Pressed
« on: October 28, 2010, 07:10:40 pm »
Hi
Can some one tell me why pressing the up key and moving the cursor has the same effect in the following code:
Thanks
Warren
Can some one tell me why pressing the up key and moving the cursor has the same effect in the following code:
Code: [Select]
#include <SFML/Graphics.hpp>
int main()
{
srand((unsigned int)time(NULL));
int x, y;
// Create main window
sf::RenderWindow App(sf::VideoMode(1200, 800), "SFML Graphics");
// Change color of background
App.Clear(sf::Color(128,128,128));
App.Display();
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Up));
{
x = rand() % 1000 + 50;
y = rand() % 600 + 50;
// Draw a shape
App.Draw(sf::Shape::Circle(x, y, 50, sf::Color::Red));
// Finally, display the on screen
App.Display();
}
}
}
return EXIT_SUCCESS;
}
Thanks
Warren