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

5. Animating our Game > Time for action – adding the background elements

Time for action – adding the background elements

Time for action – adding the background elements Add in the background and ground display objects to the drawBackground() function. Insert the objects in the group called gameGroup. local drawBackground = function() background = display.newImage( "background.png" ) background.x = 240; background.y = 160 gameGroup:insert( background ) ground = display.newImage( "ground.png" ) ground.x = 240; ground.y = 300 local groundShape = { -240,-18, 240,-18, 240,18, -240,18 } physics.addBody( ground, "static", { density=1.0, bounce=0, friction=0.5, shape=groundShape } ) gameGroup:insert( ground ) end What just happened? The background and ground display objects are placed in the function called drawBackground(). ground has a customized physical shape that is not the same size as the original display object. If the panda happens to hit the ground, it will be able to collide with it and not fall through.

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free Trial


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