我如何使缓存功能起作用?字母消失了!
function Tile(obj, stage, tipo) {
this.color = '#4c3030';
this.types();
var text = new createjs.Text(String.fromCharCode(this.obj[tipo].code), this.obj[tipo].size + "px Arial", this.obj[tipo].color);
text.x = (13 * obj.x) + 150;
text.y = (13 * obj.y) + 44;
text.textBaseline = "alphabetic";
text.cache((13 * obj.x) + 150, (13 * obj.y) + 44, 13, 13);
stage.addChild(text);
}
答案 0 :(得分:0)
该问题可能是因为您缓存了错误的坐标。缓存相对于对象是 relative ,因此,如果您是左上对齐(默认),则可以使用[x = 0,y = 0]。看来您是在使用x / y坐标,将文本放置在其父级中。
text.cache(0, 0, 13, 13);
请注意13x13的尺寸非常小,可能需要放大。
一种简单的方法是仅使用文本的边界。尽管某些字体/浏览器组合并不完美,但这是相对准确的:
var bounds = text.getBounds();
text.cache(bounds.x, bounds.y, bounds.width, bounds.height);
进行测试,然后将范围输出到控制台,您应该能够更好地了解缓存的工作原理。
干杯!