HTML and CSS Reference
In-Depth Information
},this);
this._super({
cols:this.level[0].length,
rows:this.level.length,
sheet: 'tiles'
});
var tiles =[];
for(var y=0;y<this.level.length;y++) {
tiles[y] = [];
for(var x =0;x<this.level[0].length;x++) {
var square = this.level[y][x],
frame = null,
method = this.legend[square] || "wall";
frame = this[method](x*tileSize,y*tileSize);
tiles[y].push(frame);
}
}
this.setup(tiles,false);
},
insert: function(sprite) {
this.stage.insert(sprite);
this.sprites[sprite.p.tileY][sprite.p.tileX] = sprite;
return sprite;
},
wall: function(x,y) { return TILE.WALL; },
floor: function(x,y) { return TILE.FLOOR; }
});
Now the class primarily modifies the init method to take in an asset and a stage and set up the tile map
by looking up what it should do with each tile in the legend property. Currently, only two tile types are sup-
ported, floor and wall ; each just controls the look of the tile. You'll add functionality to keep track of the
sprites at each tile location, so in anticipation of that functionality the this.sprites array is created with
the same number of rows as the main tile data. It also has a helper method for inserting sprites into the stage
that adds them to the this.sprites array.
To test this out, remove the alert and modify the code inside of the Q.scene definition for the level1
scene to read:
Q.scene('level1',new Q.Scene(function(stage) {
if(Q.width > 600 || Q.height > 600) {
stage.rescale(2);
}
stage.level = stage.insert(
Search WWH ::




Custom Search