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 – 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 both gravity and real-world physics will be applied. To add the egg object, perform the following steps:

  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

What just happened?

We have set the egg value for x with 240 + mRand( 120 ). The mRand function is equal to math.random, which will allow...

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)