浏览代码

Added a NESTileSurface class accessible through the renderer that will allow for the quick rendering of NESTiles.

dev
Bryan Miller 5 年前
父节点
当前提交
90524054d4
共有 1 个文件被更改,包括 29 次插入1 次删除
  1. +29
    -1
      app/js/ui/Renderer.js

+ 29
- 1
app/js/ui/Renderer.js 查看文件

import NESPalette from "/app/js/models/NESPalette.js"; import NESPalette from "/app/js/models/NESPalette.js";





class NESTileSurface extends ISurface{
constructor(tile, palette, palindex){
super();
this.__tile = tile;
this.__palette = (palette instanceof NESPalette) ? palette : null;
this.__pi = (palindex >= 0 && palindex < 8) ? palindex : -1;
}

get width(){return 8;}
get height(){return 8;}
get length(){return 64;}

getColor(x, y){
var ci = this.__tile.getPixelIndex(x, y);
if (this.__palette !== null){
return this.__palette.get_palette_color(this.__pi, ci);
}
return NESPalette.Default(ci);
}

getColorIndex(x, y){
return {pi:this.__pi, ci:this.__tile.getPixelIndex(x,y)};
}
}


function clear(ctx, color, cw, ch){ function clear(ctx, color, cw, ch){
if (typeof(cw) !== 'number'){ if (typeof(cw) !== 'number'){
cw = (Math.floor(ctx.canvas.clientWidth) > 0) ? cw = (Math.floor(ctx.canvas.clientWidth) > 0) ?
export default { export default {
clear: clear, clear: clear,
render: render, render: render,
renderToFit: renderToFit renderToFit: renderToFit,
NESTileSurface: NESTileSurface
}; };

正在加载...
取消
保存