@horacebury, I ran your code and edited just two lines (marked below), and it seems to achieve the effect you guys are going for:
[lua]
local physics = require( “physics” )
physics.start()
physics.setGravity(0,0)
physics.setDrawMode( “hybrid” )
local sWidth, sHeight = display.contentWidth, display.contentHeight
local stage = display.getCurrentStage()
local arena = display.newGroup()
local border = display.newRect( arena, 0, 0, sWidth*2, sHeight*2 )
border:setFillColor(0,50,0,0)
border.strokeWidth = 10
border:setStrokeColor(255,255,255)
– random fill
for i=1, 10 do
display.newCircle( arena, math.random(50, sWidth*2-50), math.random( 50, sHeight*2-50 ), math.random(1,40) ):setFillColor(0,255,0,50)
end
local player = display.newCircle( arena, 250, 250, 25 )
physics.addBody( player )
local touchBorder = 150
local xOffset, yOffset = 0, 0
local function calcTouchOffset( e )
local x, y = 0, 0
if (e.x < touchBorder) then
x = e.x - touchBorder
elseif (e.x > sWidth-touchBorder) then
x = e.x - (sWidth-touchBorder)
end
if (e.y < touchBorder) then
y = e.y - touchBorder
elseif (e.y > sHeight-touchBorder) then
y = e.y - (sHeight-touchBorder)
end
return x, y
end
function drag(e)
if (e.phase == “began”) then
e.target.hasFocus = true
local x, y = arena:contentToLocal( e.x, e.y )
e.target.touchjoint = physics.newJoint( “touch”, e.target, x, y )
stage:setFocus( e.target )
xOffset, yOffset = 0, 0
return true
elseif (e.target.hasFocus) then
if (e.phase == “moved”) then
local x,y = arena:contentToLocal(e.x, e.y) – This line is changed
e.target.touchjoint:setTarget( x, y ) – This line is changed
xOffset, yOffset = calcTouchOffset( e )
else
e.target.hasFocus = false
e.target.touchjoint:removeSelf()
e.target.touchjoint = nil
stage:setFocus( nil )
xOffset, yOffset = 0, 0
timer.performWithDelay( 150, function()
e.target:setLinearVelocity( 0, 0 )
e.target.angularVelocity = 0
end, 1 )
end
return true
end
xOffset, yOffset = 0, 0
return false
end
player:addEventListener(“touch”,drag)
function arena:update()
arena.x, arena.y = arena.x - xOffset, arena.y - yOffset
if (arena.x > 0) then
arena.x = 0
elseif (arena.x < -sWidth) then
arena.x = -sWidth
end
if (arena.y > 0) then
arena.y = 0
elseif (arena.y < -sHeight) then
arena.y = -sHeight
end
end
function enterFrame()
arena:update()
end
Runtime:addEventListener(“enterFrame”, enterFrame)
[/lua]