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
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

6. Game #5, Balls Out! > Time for action — creating the ball

Time for action — creating the ball

As it can be destroyed by the enemy, we will wrap up its creation inside its own method. That makes this process reusable.

  1. Insert the method CreateBall into our game class.
    Method CreateBall:Int ()
    
  2. The ball is a field set inside the game class, so assign an image object to it through the CreateImage method. It will be placed in the lower center of the canvas:
    ball = eng.CreateImage(atlas,64,0,32,32,cw/2,ch-50)
    
  3. Set its radius and scale:
    ball.SetRadius(16)
    ball.SetScale(1.5)
    
  4. Now, set the friction property. Once in movement, we don't want it to move forever, but slow down once you don't tilt the device:
    ball.SetFriction(0.8)
    
  5. Assign it to the game layer:
    ball.SetLayer(layerGame)
    
  6. To detect a collision, set its collision group to grpBall, so that it can collide with the enemies and the tiles:
    ball.SetColGroup(grpBall)
    ball.SetColWith(grpEnemy, True)
    ball.SetColWith(grpTile, True)
    

  

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