【发布时间】:2015-01-13 10:29:36
【问题描述】:
我无法在这个 ChessBoard 视图中看到我的资产图片,尽管导航控制台没有显示任何错误:
enyo.kind({
name: "PositionView",
published: {
fen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
cellsize: 32,
color: "#CCC"
},
fit: true,
components: [
{
name: "canvas",
kind: "enyo.Canvas",
attributes: {width: 10, height: 10}
}
],
create: function() {
this.inherited(arguments);
},
rendered:function(){
this.inherited(arguments);
this.computeCellSize();
this.drawGrid();
this.drawPieces();
this.$.canvas.update();
},
drawGrid: function() {
for (var line=0; line < 8; line++){
for (var col=0; col < 8; col++){
var compName = "abcdefgh"[col] + (8-line);
var bgcolor = ((line+col)%2 == 0) ? "#CF3" : "#630";
this.$.canvas.createComponent({
kind: "enyo.canvas.Rectangle",
bounds:{t:(line*this.cellsize), l:(col*this.cellsize), w:this.cellsize, h:this.cellsize},
color:bgcolor,
name: compName
});
}
}
},
drawPieces: function(){
var x = 3*this.cellsize;
var y = 4*this.cellsize;
this.$.canvas.createComponent({
kind: "enyo.canvas.Image",
bounds:{t:y, l:x, w:this.cellsize, h:this.cellsize},
src: "assets/wn.svg"
});
},
computeCellSize: function(){
var screenWidth = enyo.dom.getWindowWidth();
var screenHeight = enyo.dom.getWindowHeight();
var minSize = screenWidth < screenHeight ? screenWidth : screenHeight;
this.cellsize = Math.floor(minSize * 1.0 / 8);
this.$.canvas.setAttribute('width', 8*this.cellsize);
this.$.canvas.setAttribute('height', 8*this.cellsize);
}
});
您应该已经注意到,我正在使用方法 drawGrid() 动态地制作网格单元(这很好用),但是方法 drawPieces() 似乎不起作用,因为我看不到图片。
为没有使用 JsFiddle 道歉,这是因为我不知道如何调整我的项目以使其适合它。
【问题讨论】:
标签: enyo