HTML and CSS Reference
In-Depth Information
In this case the engine would take over the handling of the game loop. A slightly more full-featured game might
look like listing 9-2 .
Listing 9-2: A more complicated API example
var MyGame = Quintus()
.include("Input,Sprites,Scenes")
.setup();
var spriteType1 = MyGame.CanvasSprite.extend({
// Overrides for this type of object
});
var spriteType2 = MyGame.CanvasSprite.extend({
// Overrides for this type of object
});
MyGame.load([ 'asset1.png', 'asset2.png', 'sprites.json'],function() {
var scene1 = new MyGame.Scene(function(stage) {
stage.add(new MyGame.SpriteType1({ ... Options .. });
stage.add(new MyGame.SpriteType2({ ... Options .. });
});
MyGame.stageScene(scene1);
});
Here the game extends the base Quintus functionality with the Quintus.Input , the Quin-
tus.Sprites , and the Quintus.Scenes extensions and then creates a couple of reusable sprite types.
The game loads multiple assets, including a spritesheet, and then when those are loaded it creates a new scene
object. Finally, it stages the scene, which starts the scene-based game loop (if it hasn't already been started) and
handles the updating and rendering of the scene.
Starting the Engine Code
With a developer-friendly API for the engine defined, open up quintus.js and start writing the initial code
that acts as a base for all the engine code to follow. Quintus takes a page from jQuery's playbook and uses a
single method as a factory method and a container object for extensions to the engine.
To create a new game with Quintus, just call the Quintus method and then use and extend that individual
object with additional functionality. Because multiple instances of Quintus might exist on a single page, you
need to load any extensions to the engine in an individual instance.
To achieve this, you can create a function called Quintus that creates, augments, and finally returns a new
object. Listing 9-3 shows the initial structure of the engine.
Listing 9-3: The basic engine structure
var Quintus = function(opts) {
var Q = {};
 
 
 
 
Search WWH ::




Custom Search