Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

7. Physics: Falling Objects > Time for action – adding the egg object

Time for action – adding the egg object

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 the gravity and real-world physics will be applied.

  1. Create a new local function called eggDrop().
        local eggDrop = function()
  2. 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 )
  3. Add in the postCollision event for the egg display object.
          egg.postCollision = onEggCollision
          egg:addEventListener( "postCollision", egg )
        end
    Time for action – adding the egg object

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint