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 the egg collision


We have handled collisions in the previous sample games we created. Handling postcollisions requires the introduction of force to execute the completion of a postcollision event:

  1. Create a new local function called onEggCollision() with two parameters called self and event:

        local onEggCollision = function( self, event )
  2. Create an if statement when the force is greater than 1 and include not self.isHit. Add in the eggCaughtSound sound effect:

          if event.force > 1 and not self.isHit then
            audio.play( eggCaughtSound )
  3. Make self invisible and inactive, and replace it with the friedEgg display object:

            self.isHit = true
            print( "Egg destroyed!")
            self.isVisible = false
            friedEgg.x = self.x; friedEgg.y = self.y
            friedEgg.alpha = 0
            friedEgg.isVisible = true
  4. Create a function that transitions the friedEgg display object and fades it off the stage by using the onComplete command:

            local fadeEgg...
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)