HTML and CSS Reference
In-Depth Information
point: function(x, y) {
//from display to world coordinates
x -= this.displayWidth()>>1;
y -= this.displayHeight()>>1;
x *= this.scale
y *= this.scale
x += this.centerX;
y += this.centerY;
return {x:x, y:y}
},
round: function() {
this.centerX = Math.round(this.centerX);
this.centerY = Math.round(this.centerY);
}
}
Renderer
After all that logic, at last you can draw something. The renderer object's drawing is shaped not only by the camera;
the renderer also stores something in cache to make the rendering process faster. Nevertheless, you will not use
caching in this baseline implementation. If you like, you can set up two canvases, and one renderer will work with
two cameras. The renderer calculates the rectangle of tiles on the map that needs to be drawn and processes every tile
twice during the cycle.
The process of drawing autotiles can be described by two methods: auto determines the magic number, which
depends on the neighboring cells, and render takes that magic number and renders the tile. If the rendering process
starts to slow down the application, magic numbers can be stored in cache and recalculated whenever the tile is
changed. For C/C++ applications the time required to calculate the magic number is comparable to the actual
rendering time. Both methods depend on a tile, so let's add them as functions to Tile and override this later:
var Renderer = function(map, sprites) {
this.map = map
this.tiles = map.tiles
this.sprites = sprites
}
Renderer.prototype = {
//renderer is different from camera, cause render can store cache on some info, not
dependent on a camera
render: function(camera) {
var displayWidth = camera.displayWidth()
var displayHeight = camera.displayHeight()
//get view rect on map
var r = camera.clientRect();
var map = this.map
var context = this.context = camera.context()
context.fillStyle = "black"
context.fillRect(0, 0, displayWidth, displayHeight);
 
Search WWH ::




Custom Search