2020-02-29 13:45:56 +01:00
|
|
|
var Container = require("./Container"),
|
|
|
|
TileSprite = require("./TileSprite")
|
|
|
|
;
|
2020-01-17 13:26:50 +01:00
|
|
|
|
|
|
|
class TileMap extends Container {
|
|
|
|
constructor(tiles, mapW, mapH, tileW, tileH, texture) {
|
|
|
|
super();
|
|
|
|
this.mapW = mapW;
|
|
|
|
this.mapH = mapH;
|
|
|
|
this.tileW = tileW;
|
|
|
|
this.tileH = tileH;
|
|
|
|
this.w = mapW * tileW;
|
|
|
|
this.h = mapH * tileH;
|
|
|
|
|
|
|
|
this.children = tiles.map((frame, i) => {
|
|
|
|
const s = new TileSprite(texture, tileW, tileH);
|
|
|
|
s.frame = frame;
|
|
|
|
s.pos.x = i % mapW * tileW;
|
|
|
|
s.pos.y = Math.floor(i / mapW) * tileH;
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-29 13:45:56 +01:00
|
|
|
module.exports = TileMap;
|