Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

7. Physics: Falling Objects > Time for action – moving the character

Time for action – moving the character

Eggs will be falling in all different areas of the screen from the sky. Let's prepare our main character to move through all potential areas on te screen.

  1. Set up a new local function called moveChar() with an event parameter.
        local moveChar = function(event)
  2. Add in the accelerometer movement for the character.
          charObject.x = display.contentCenterX - 
            (display.contentCenterX * (event.yGravity * 3))
  3. Create character boundaries where they moves on the screen. This enables the character to stay within the game screen and not go past the offscreen boundaries.
          if((charObject.x - charObject.width * 0.5) < 0) then
            charObject.x = charObject.width * 0.5
          elseif((charObject.x + charObject.width * 0.5) >
                 display.contentWidth) then
            charObject.x = display.contentWidth - charObject.width * 
              0.5
          end
        end

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial