O'Reilly logo

Core HTML5 Canvas: Graphics, Animation, and Game Development by David Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required