..............
Printable View
..............
You need to debug your code to see what is happening.Quote:
sometimes it moves two tiles in the grid even though I'm not holding down an arrow key.
Add some printlns to show the values of the variables as they are changed and as they are used to move the image.
..............
Look at your logic to see if the image's next movement will go past the bounds of the grid and stop its moving at that point. For example if it is at 31 and moves by 2 it will skip over 32.Quote:
it sometimes doesn't hit zero,
So before the move test if the change of position will move the image past its stopping point.
..............
Look at the logic where you change the x,y values for a move.
Check if the new position will cross a boundary and if the movement should stop.
If it should stop, set the new location to be on the boundary and signal a stop.
..............
How else would you change the movement into the next postion if it was past where you want it to stop?Quote:
It snaps into place
I did not say to continue using the % 32 logic. Perhaps that is not the way to recognize where the boundaries are.
..............
There are usually more than one way to solve a problem.
Simpler is often better.