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:
Create a new local function called
onEggCollision()
with two parameters calledself
andevent
:local onEggCollision = function( self, event )
Create an
if
statement when the force is greater than1
and includenot
self.isHit
. Add in theeggCaughtSound
sound effect:if event.force > 1 and not self.isHit then audio.play( eggCaughtSound )
Make
self
invisible and inactive, and replace it with thefriedEgg
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
Create a function that transitions the
friedEgg
display object and fades it off the stage by using theonComplete
command:local fadeEgg...