Hello everybody,
I have a page of my app where an object is draggable, but with the basic drag functions found in the Corona examples the user can move the object wherever he wants, even outside the screen, is it possible to set a limit in space (without using collisions) ? It would be great to set a virtual 'box' inside which the object can move.
I'm using the code from the 'DragMe' sample code
Thank you
Ray
Create an enterFrame function and check the x/y values of the object. If the x/y values are higher than you want them to be then set the objects x/y to the max
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| local function limit()
local x = object.x
local y = object.y
if(x > 100) then
object.x = 100
elseif(x < 50) then
object.x = 50
end
if(y > 100) then
object.y = 100
elseif(y < 50) then
object.y = 50
end
end
Runtime:addEventListener("enterFrame", limit) |
It works perfectly, thank you !
Ray