Hi,
I want to stop a drag object going off screen.
I’ve found a function to do this but its interfering with the next page and I’m wondering why or if there’s a better function I could use?
any help, greatly appreciated
Steve
[lua]local map = display.newImage (“images/map.png”)
map.x = 720
map.y = 980
function onTouch( event )
local t = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end
return true
end
map:addEventListener( “touch”, onTouch )
local function wrapit (event)
if map.x < 10 then
map.x = 10
elseif map.x > 738 then
map.x = 738
elseif map.y < 10 then
map.y = 10
elseif map.y > 994 then
map.y = 994
end
end[/lua] [import]uid: 97656 topic_id: 17343 reply_id: 317343[/import]
[import]uid: 52491 topic_id: 17343 reply_id: 65640[/import]