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

5. Animating our Game > Time for action – creating the panda character

Time for action – creating the panda character

We need to set up the panda collision event and animate it with the sprite sheet accordingly.

  1. We need to create a local function that will introduce the collision and touch events for the panda. We shall call it createPanda().
    local createPanda = function()
  2. When the panda collides with the stars, use onPandaCollision() with the parameters self and event. Reload panda every time a collision occurs with the stars or the edge of the screen by using callNewRound().
      local onPandaCollision = function( self, event )
        if event.phase == "began" then
          
          if panda.isHit == false then
          
            panda.isHit = true
            
            if event.other.myName == "star" then
              callNewRound( true, "yes" )
            else
              callNewRound( true, "no" )
            end
                    
            if event.other.myName == "wall" then
              callNewRound( true, "yes" )
            else
              callNewRound( true, "no" )
            end
          
          elseif panda.isHit then
            return true
          end
        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