Why check a desired location beforehand rather than the current location of the player?
Just curious, I never done it your way before.
It seems like you created a bug when you sent the desired position by to the last location.
It is not a graphical error.
I am pretty sure the bug is below here. It seems like juggling too many variable states, right?
why are you changing desired back to the current position?
x = dx;
y = dy;
// why are you setting current position back to the last position?
lx = x;
ly = y;
No it was a graphical error. If you don't believe me, try it with floats. And I think that you arent understanding the order in which code is executed. So first I set:
x = dx;
y = dy;
Then after that I set:
lx = x;
ly = y;
Which is the same as:
lx = dx;
ly = dy;
because I have already set the position variables equal to the desired variables. Might want to read up on some things before you start throwing false claims ;)
I was merely questioning why you are checking a desired location when you can be doing it in a current location. I am not saying your code is wrong. I was curious about your approach. I am not making any false claims about anything...
Confused about why I was down-voted for my own curiosity...
Edit: I tested your code in my code base that is similar to yours and it can ruin an object initial position upon its creation in the game.
The bug will happen as long as you are checking collisions regardless if a rectangular intersections happens.
Basically when I tested your code, the position I created for my object was changed upon loading my game.
Strange how you did not encounter a bug like I did.
My code:
position.setX(dx);
position.setY(dy);
lx = (int) position.getX();
ly = (int) position.getY();
Your code:
x = dx;
y = dy;
lx = x;
ly = y;