local ballBuffer = 5 --- Assumes that background image is of size --- XXX --- XOX --- Where each character is the size of the screen, and 'O' is the default view. function getDrawOffset(screenW, screenH, ballX, ballY) local offsetX, offsetY if ballY < ballBuffer then offsetY = math.max(ballBuffer, -1 * (ballY - ballBuffer)) else offsetY = 0 end if ballX > 0 and ballX < (screenW - ballBuffer) then offsetX = 0 elseif ballX < ballBuffer then offsetX = math.max(-1 * screenW, -1 * (ballX - ballBuffer)) elseif ballX > (screenW - ballBuffer) then offsetX = math.min(screenW * 2, -1 * (ballX - ballBuffer)) end return offsetX, offsetY end