HTML and CSS Reference
In-Depth Information
Listing 5-1. The SpriteProto definition
function SpriteProto(){
this.load= function(filename,w,h)
var targetSpriteProto = this;
this.size.w = w;
this.size.h = h;
var img = new Image();
img.onload = function(){
targetSpriteProto.imgHandle = img;
img.src = filename;
For most game build-chains, you'll generally create some sort of designer or artist-centric view of the world
ahead of time. That is, before this level is actually loaded by the user, you have a pretty good idea what assets will be
needed to load, simulate, and display this level. As such, you don't define a complex asset dependency hierarchy here,
but rather brute-force the loading of your basic proto-sprites so that they can be used by object instances later. During
your initialization, you fill the globally accessible protoSprites array using the loadProtos function (see Listing 5-2).
Listing 5-2. Loading a set of prototype images
var protoSprites = new Array();
function loadProtos()
//technically, this should be an atlas definition!
var imgs=[
for(var i =0; i < imgs.length; i++)
var sp = new SpriteProto();
Note that for your purposes, you don't just list the path to the image, but also the width and height of the bitmap
in pixels. These image-specific bounding conditions are important for gross-level picking that we'll discuss a bit later
in the bounding boxes section.
Search WWH ::

Custom Search