i am working on a Pong game with multiplayer, currently i am testing some Funktions but unfortunately
it Keeps closing if i move the mouse in a certain way(slowly or fast it doesnt happen always)
while (window.isOpen())
{
/* Print out Information about 'player'
printf("Position-Y: %d\n", rectangle.getPosition().y);
printf("Size-Y %d\n", (int)rectangle.getSize().y);
printf("Origin-y: %d\n", rectangle.getOrigin().y);
Sleep(500);
*/
while (window.pollEvent(event))
{
// Escape-options
if(event.type == sf::Event::Closed)
{
window.close();
}
if(event.key.code == sf::Keyboard::Escape)
{
window.close();
}
// Determining Event-Type
if(event.type == event.KeyReleased)
{
//only to test how to change the lenght of the rectangle
if(event.key.code == sf::Keyboard::S)
{
rectangle.setSize(sf::Vector2f(rectangle.getSize().x, rectangle.getSize().y *2));
}
}
}
if(abs(rectangle.getPosition().y - sf::Mouse::getPosition(window).y) > 5)
{
if(rectangle.getPosition().y - sf::Mouse::getPosition(window).y > 0)
{
rectangle.setPosition(0, rectangle.getPosition().y -(1*acceleration));
if(acceleration < 3){ acceleration++;}
}else
{
rectangle.setPosition(0, rectangle.getPosition().y +(1*acceleration));
if(acceleration < 3){ acceleration++;}
}
}else
{
//this part could be wrong but i suppose it has nothing to do with my problem
if(acceleration >= 3)
{
acceleration = 1;
}
}
i only inserted the part where i think the problem might be, the rest is only initializing and defining variables
Thank's for any Help