- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
/* eslint-disable no-unused-vars */
import pool from "./../../../system/pooling.js";
import TMXLayer from "./../TMXLayer.js";
import Bounds from "./../../../physics/bounds.js";
/**
* @classdesc
* The map renderer base class
*/
export default class TMXRenderer {
/**
* @param {number} cols - width of the tilemap in tiles
* @param {number} rows - height of the tilemap in tiles
* @param {number} tilewidth - width of each tile in pixels
* @param {number} tileheight - height of each tile in pixels
*/
constructor(cols, rows, tilewidth, tileheight) {
this.cols = cols;
this.rows = rows;
this.tilewidth = tilewidth;
this.tileheight = tileheight;
this.bounds = new Bounds();
}
/**
* return true if the renderer can render the specified map or layer
* @param {TMXTileMap|TMXLayer} component - TMX Map or Layer
* @returns {boolean}
*/
canRender(component) {
return (
/*
// layers can have different size within
// the same maps, so commenting these two lines
(this.cols === component.cols) &&
(this.rows === component.rows) &&
*/
(this.tilewidth === component.tilewidth) &&
(this.tileheight === component.tileheight)
);
}
/**
* return the bounding rect for this map renderer
* @param {TMXLayer} [layer] - calculate the bounding rect for a specific layer (will return a new bounds object)
* @returns {Bounds}
*/
getBounds(layer) {
let bounds = layer instanceof TMXLayer ? pool.pull("Bounds") : this.bounds;
bounds.setMinMax(
0, 0,
this.cols * this.tilewidth,
this.rows * this.tileheight
);
return bounds;
}
/**
* return the tile position corresponding to the specified pixel
* @param {number} x - X coordinate
* @param {number} y - Y coordinate
* @param {Vector2d} [v] - an optional vector object where to put the return values
* @returns {Vector2d}
*/
pixelToTileCoords(x, y, v) {
return v;
}
/**
* return the pixel position corresponding of the specified tile
* @param {number} col - tile horizontal position
* @param {number} row - tile vertical position
* @param {Vector2d} [v] - an optional vector object where to put the return values
* @returns {Vector2d}
*/
tileToPixelCoords(col, row, v) {
return v;
}
/**
* draw the given tile at the specified layer
* @param {CanvasRenderer|WebGLRenderer} renderer - a renderer object
* @param {number} x - X coordinate where to draw the tile
* @param {number} y - Y coordinate where to draw the tile
* @param {Tile} tile - the tile object to draw
*/
drawTile(renderer, x, y, tile) {
}
/**
* draw the given TMX Layer for the given area
* @param {CanvasRenderer|WebGLRenderer} renderer - a renderer object
* @param {TMXLayer} layer - a TMX Layer object
* @param {Rect} rect - the area of the layer to draw
*/
drawTileLayer(renderer, layer, rect) {
}
}
/* eslint-enable no-unused-vars */