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 – launching the panda


Let's add a touch event for the panda so that it flings toward the stars. The powerShot object will play a role in helping the player visualize how much power needs to be applied to the panda, before it launches into the air.

  1. Implement touch events for the panda. Create a local function called onScreenTouch() with an event parameter:

    local onScreenTouch = function( event )
  2. With gameIsActive initiated, add in an if statement for when the touch event starts, by using event.phase == "began". During this event, use the "crouch" animation set to prepare panda for launch:

      if gameIsActive then
        if event.phase == "began" and panda.inAir == false then
    
          panda.y = 225
          panda.isReady = true
          powerShot.isVisible = true
          powerShot.alpha = 0.75
          powerShot.x = panda.x; powerShot.y = panda.y
          powerShot.xScale = 0.1; powerShot.yScale = 0.1
    
          arrow.isVisible = true
    
          panda:setSequence("crouch")
          panda:play()
  3. Add an elseif statement...