Set A boundary that objects can not move beyond

I have multiple draggable objects that can be moved around the screen. I want to set a boundary so they can not be dragged off screen. I can’t really find what I’m looking for to do this. [import]uid: 208811 topic_id: 35786 reply_id: 335786[/import]

Using the drag tutorial posted by Corona (http://www.coronalabs.com/blog/2011/09/24/tutorial-how-to-drag-objects/) you can set the absolute values for your x and y variables like so:

[lua]
elseif event.phase == “moved” then

local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY

self.x, self.y = x, y – move object based on calculations above
if self.x > 500 then
self.x = 500
end
if self.x < 100 then
self.x = 100
end
end
[/lua]

It’s not really a boundary, but it will keep you from dragging the items past a certain point, which is just as good. you could just set an image at the code boundary you specify to give it the appearance of a physical boundary.

[import]uid: 135394 topic_id: 35786 reply_id: 142382[/import]

double post [import]uid: 135394 topic_id: 35786 reply_id: 142383[/import]

Using the drag tutorial posted by Corona (http://www.coronalabs.com/blog/2011/09/24/tutorial-how-to-drag-objects/) you can set the absolute values for your x and y variables like so:

[lua]
elseif event.phase == “moved” then

local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY

self.x, self.y = x, y – move object based on calculations above
if self.x > 500 then
self.x = 500
end
if self.x < 100 then
self.x = 100
end
end
[/lua]

It’s not really a boundary, but it will keep you from dragging the items past a certain point, which is just as good. you could just set an image at the code boundary you specify to give it the appearance of a physical boundary.

[import]uid: 135394 topic_id: 35786 reply_id: 142382[/import]

double post [import]uid: 135394 topic_id: 35786 reply_id: 142383[/import]