local touchBeginPoint = nil
local function onTouchBegan(x, y)
cclog("onTouchBegan: %0.2f, %0.2f", x, y)
-- CCTOUCHBEGAN event must return true
touchBeginPoint = {x = x, y = y}
return true
end
local function onTouchMoved(x, y)
cclog("onTouchMoved: %0.2f, %0.2f", x, y)
if touchBeginPoint then
local cx, cy = backGroundSp:getPosition()
backGroundSp:setPosition(cx + x - touchBeginPoint.x,
cy + y - touchBeginPoint.y)
touchBeginPoint = {x = x, y = y}
end
end
local function onTouchEnded(x, y)
cclog("onTouchEnded: %0.2f, %0.2f", x, y)
end
local function onTouch(eventType, x, y)
if eventType == "began"then
return onTouchBegan(x, y)
elseif eventType =="moved" then
return onTouchMoved(x, y)
else
return onTouchEnded(x, y)
end
end
layer:registerScriptTouchHandler(onTouch)
layer:setTouchEnabled(true)