Lua blasterball-like app, offscreen problem.

i have just finished the first level of the app, and i have a problem with my paddle to return the ball. the paddle moves with my finger, on the x-axis, but does not stop at the screen's edge. my code:

local paddle = display.newImageRect (paddle, {"paddle.png", 120, 33})
paddle.x = 159
paddle.y = 275
function movePaddle( event )
paddle.x = event.x
paddle.y = 275
end
Runtime:addEventListener("touch", movePaddle)

the question is is there a way to limit the movement range to say 300 pixels, without messing up on bigger or smaller screens?

the paddle.png is just a paint png that is a 320x100 gray square. nothing advanced about it, just me being hopeful for a simple fix.

In your movePaddle function, perhaps wrap the code to move the paddle in an if then statement so it only is moveable to an X position on the left and X position on the right.

Something like....

1
2
3
4
5
6
function movePaddle( event )
     if event.x >= 50 and event.x <= 300 then
       paddle.x = event.x
       paddle.y = 275
     end
end

much appreciated. it worked well.

views:1490 update:2011/10/5 21:23:48
corona forums © 2003-2011