Right now, the paddle does not move at all. There are no coordinates set to translate on the screen, so let's create that.
Underneath the
addGameScreen()
function, create a new function calleddragPaddle(event)
.function dragPaddle(event)
Next, we'll focus on moving the paddle side to side within the boundary of the game screen.
if isSimulator then if event.phase == "began" then moveX = event.x - paddle.x elseif event.phase == "moved" then paddle.x = event.x - moveX end if((paddle.x - paddle.width * 0.5) < 0) then paddle.x = paddle.width * 0.5 elseif((paddle.x + paddle.width * 0.5) > display.contentWidth) then paddle.x = display.contentWidth - paddle.width * 0.5 end end end
Add in the preceding block of code to enable paddle movement in the simulator and then close the function. The reason for adding this block is because the simulator does not support accelerometer...