We have handled collisions in the previous sample games we created. Handling post-collisions requires the introduction of force to execute the completion of a post-collision event.
Create a new local function called
onEggCollision()
with two parameters calledself
andevent
.local onEggCollision = function( self, event )
Create an
if
statement when force is greater than1
andnot
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 makes it fade on the stage using theonComplete
command.local fadeEgg = function...