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

Chapter 9. Game Development > 9.3. A Pinball Game

9.2.2. The Ungame’s Game Loop

The ungame creates a Game instance and reimplements paintUnderSprites() and paintOverSprites(). The ungame doesn’t have any sprites, but the game engine invokes paintUnderSprites() and paintOverSprites() anyway, as shown in Example 9.11.

Example 9.11. Painting over and under sprites


var game = new Game('ungame', 'gameCanvas'),
    ...

game.paintOverSprites = function () {
   paintNearCloud(game.context, 120, 20);
   paintNearCloud(game.context, game.context.canvas.width+120, 20);
};

game.paintUnderSprites = function () {

   // Background erased by game engine's clearScreen()

   if (!gameOver && livesLeft === 0) {
      over();
   }
   else {
      paintSun(game.context);
      paintFarCloud(game.context, 20, 20);
      paintFarCloud(game.context, game.context.canvas.width+20, 20);

      if (!gameOver) {
         updateScore();
      }

      updateLivesDisplay();
   }
};
...

game.start();


  

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