I have a little problem…
Here is my touchListener, if I touch left/right half my object should rotate continuously if I hold but stop if I let go. As of now, it starts to rotate and doesn’t stop when touch phase “ended”. If I touch again it increase the speed…
I just want it to rotate only as long as I hold on either side of the screen, am I missing out on some basics here or what?!?
local centerX = display.contentWidth/2 local centerY = display.contentHeight/2 local runtime = 0 local function getDeltaTime() local temp = system.getTimer() --Get current game time in ms local dt = (temp-runtime) / (1000/60) --60fps or 30fps as base runtime = temp --Store game time return dt end local dt = getDeltaTime() local group = display.newGroup() local bg = display.newRect(0, 0, \_W, \_H) bg:setFillColor(0, 0, 0,255) local rect = display.newRect(group, centerX, centerY, 50, 50) rect:setFillColor(220, 20, 220, 255) group:setReferencePoint(display.CenterReferencePoint) local function touchListener(event) local phase = event.phase local target = event.target local function update() if event.x \> centerX then group.rotation = group.rotation + (1\*dt) elseif event.x \< centerX then group.rotation = group.rotation - (1\*dt) end end if phase == "began" then Runtime:addEventListener("enterFrame", update) elseif phase == "moved" then elseif phase == "ended" or phase == "cancelled" then Runtime:removeEventListener("enterFrame", update) end return true end bg:addEventListener("touch",touchListener)