Add some thing like this into your loop: (y=y direction on screen) (x=x direction on screen) If x<(minimum screen value) Then:(min screen value)->x If x>(max screen value) Then:(max screen value)->x If y<(minimum screen value) Then:(min screen value)->y If y>(max screen value) Then:(max screen value)->y That should work, but make sure you add this code to your main loop.