Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By : Michelle M Fernandez
Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By: Michelle M Fernandez

Overview of this book

Table of Contents (19 chapters)
Corona SDK Mobile Game Development Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – dragging the paddle in the simulator


Right now, the paddle does not move at all. There are no coordinates set that will allow the paddle to move side to side on the screen. So let's create them by performing the following steps:

  1. Underneath the addGameScreen() function, create a new function called dragPaddle(event):

    function dragPaddle(event)
  2. Next, we'll focus on moving the paddle side to side within the boundary of the game screen. Add in the following 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 events:

      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...