Imagine a world, full of falling eggs. It's not entirely too realistic, but in this game, we're creating this element. At least, we'll be making sure that both gravity and real-world physics will be applied. To add the egg object, perform the following steps:
Create a new local function called
eggDrop()
:local eggDrop = function()
Add in the
egg
display object properties:local egg = display.newImageRect( "egg.png", 26, 30 ) egg.x = 240 + mRand( 120 ); egg.y = -100 egg.isHit = false physics.addBody( egg, "dynamic",{ density=eggDensity, bounce=0, friction=0.5, shape=eggShape } ) egg.isFixedRotation = true gameGroup:insert( egg )
Add in the
postCollision
event for theegg
display object:egg.postCollision = onEggCollision egg:addEventListener( "postCollision", egg ) end