Hello, here’s the code ( you can put it into a main.lua and it should work… )
local physics = require("physics") physics.start() ------------------------------------------------------------------------------------------------------------ local touchLeft = display.newRect( display.contentCenterX - 79.8, display.contentCenterY, 160, 570 ) touchLeft.alpha = 0.2 ------------------------------------------------------------------------------------------------------------ local stopBoxLeft = display.newRect( -3, display.contentCenterY, 5, 40 ) physics.addBody( stopBoxLeft, "static", { bounce = 0 }) stopBoxLeft.isSleepingAllowed = false ------------------------------------------------------------------------------------------------------------ local stopBoxRight = display.newRect( 323, display.contentCenterY, 5, 40 ) physics.addBody( stopBoxRight, "static", { bounce = 0 }) stopBoxRight.isSleepingAllowed = false ------------------------------------------------------------------------------------------------------------ local boxLeft = display.newRect( 15, display.contentCenterY, 30, 30 ) boxLeft:setFillColor( 1, 0, 0 ) physics.addBody( boxLeft, "dynamic", { bounce = 0 } ) boxLeft.gravityScale = 0 boxLeft.myName = "boxLeft" boxLeft.isSleepingAllowed = false ------------------------------------------------------------------------------------------------------------ local function moveLeftToRight(event) if event.phase == "began" then boxLeft:setLinearVelocity( 200, 0 ) elseif event.phase == "ended" then boxLeft:setLinearVelocity( -200, 0 ) elseif event.phase == "cancelled" then boxLeft:setLinearVelocity( -200, 0 ) end end touchLeft:addEventListener( "touch", moveLeftToRight ) ------------------------------------------------------------------------------------------------------------
So when you touch the faded white on the left then the box moves to the right and when you let go then it goes back to the left… But if you touch the left and slide your finger to the right then cancelled phase doesnt get called… Any ideas why? Thanks!!