This may be an uneducated question - or an odd one of the kind.
My question is why this code doesn't work:
if (up == true)
{
SDL_Delay(pause_t);
player.setY(player.velocity - player.getY());
}
if (left == true)
{
SDL_Delay(pause_t);
player.setX(player.velocity - player.getX());
}
However, this code does work:
if (up == true)
{
SDL_Delay(pause_t);
player.setY(player.getY() - player.velocity);
}
if (left == true)
{
SDL_Delay(pause_t);
player.setX(player.getX() - player.velocity);
}
The difference between the two codes is that in the first example, I am subtracting a part firstly (the velocity of the object) before calling the position function. What happens when I run this code is that it doesn't move 1 on the axis, but rather 10. The size of the Y axis is above 10, so I am not actually subtracting its own coordinates.
However, in the second piece of code, I am subtracting the velocity in the end, after having called my position function. What happens with the second piece of code is that the object moves one pixel (velocity's integer value).
To those who should wonder what I am trying to do, these are controls for my openGL game. It's for moving an object.
And for the record, this is not an important question. My code does work. I am simply curious why it works the way it does.