Heylo,
I’ve got a level and the player drags it around to look around.
I dont want the player to look outside of the levels boundaries.
I used this piece of code.
local function drag(e)
if (e.phase == "moved") then
if (game.x \< 1 and game.x \> -481) then
game.x = e.x - touchposx
end
if (game.y \< 1 and game.y \> -321) then
game.y = e.y - touchposy
end
end
And then if withing the boundary the player can drag around.
For the most part it works well, but when the player reaches a boundary it sticks to that boundary and can no longer be dragged by that axis.
This is because, for example, game.x has touched 0 and now that part of the code doesn’t work. And since you can’t drag on that axis, you can’t get it out of 0.
I attempted this in the same function above the previous code:
if (game.x \> 0) then
game.x = 0;
return true
elseif (game.x \< -480) then
game.x = -480;
return true
elseif (game.y \> 0) then
game.y = 0;
return true
elseif (game.y \< -320) then
game.y = -320;
return true
end
However this causes a snapback motion as it snapped back to 0, then the player moves his finger slightly changing it beyond the boundary then it snapping back again.
Is there a way to prevent the player from dragging the background past the boundary without it getting stuck or snapback?
Thanks Matt. [import]uid: 91798 topic_id: 16071 reply_id: 316071[/import]
