(libGDX, Java) I'm trying to make an object move from one side of the screen to the other and when it reach the other side it start over. The code I use for the action:
if (position.x < 300) {
position.x -= 1;
}
if (position.x == -70) {
position.x = 131;
}
position is a Vector2. 1 is the movement speed of the object and where I have the problem. The loop work fine if the position.x -= A WHOLE NUMBER, but if I want it to be 0.3f, 1.5f... the loop won't work and the object just continue moving. How can if fix it so that the loop will work with any number?