Reader small image

You're reading from  Corona SDK Mobile Game Development: Beginner's Guide

Product typeBook
Published inMar 2015
Publisher
ISBN-139781783559343
Edition1st Edition
Tools
Right arrow
Author (1)
Michelle M Fernandez
Michelle M Fernandez
Right arrow

Time for action – creating star collisions


Star collisions need to be made and removed from the stage so that points can be accumulated for the player.

  1. Create a function for the star collision called onStarCollision() and have a self and event parameter:

    local onStarCollision = function( self, event )
  2. Add the if statements that remove the stars children from the game screen when a collision is made. Increment the score by 500 for each star removed from the screen. Close the function with end:

      if event.phase == "began" and self.isHit == false then
    
        self.isHit = true
        print( "star destroyed!")
        self.isVisible = false
    
        stars.numChildren = stars.numChildren - 1
    
        if stars.numChildren < 0 then
          stars.numChildren = 0
        end
    
        self.parent:remove( self )
        self = nil
    
        local newScore = gameScore + 500
        setScore( newScore )
      end
    end

What just happened?

The star collision occurs on first contact with if event.phase == "began" and self.isHit == false, assuming the...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Corona SDK Mobile Game Development: Beginner's Guide
Published in: Mar 2015Publisher: ISBN-13: 9781783559343

Author (1)