I have a weird problem. I Just started with SFML yesterday and wanted to make a simple game for the beginning, now i want to move a rectangle object 0.5pixel in x and y with every loop, so when i write
ball.move(0.5, 0.5);
everything works as expected, but if i put x and y into variables it stops working, anyone know what causes this behavior?
Here is the full code for reference:
#include <SFML/Graphics.hpp>
#include <stdio.h>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(1280, 718), "", sf::Style::Close);
sf::RectangleShape ball(sf::Vector2f(15, 15));
ball.setPosition(640, 359);
int p1score = 0;
int p2score = 0;
int xspeed = 0.5;
int yspeed = 0.5;
int x = ball.getPosition().x;
int y = ball.getPosition().y;
//mainloop
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
//close
if (event.type == sf::Event::Closed)
{
window.close();
}
}
window.clear(sf::Color::Black);
ball.move(xspeed, yspeed);
window.draw(ball);
window.display();
}
return 0;
}