【发布时间】:2017-02-11 03:51:26
【问题描述】:
我正在使用 EaselJS 在 JS 中编写一个简单的游戏。我尝试保持一切面向对象,以保持游戏的同步状态、EaselJS 对象的状态以及我的画布上显示的内容。我希望有可能通过更改属性来更改画布上显示的形状的笔触颜色。我在文档append()here 中找到了,但我无法让它工作。
这是我目前所取得的成就:
形状定义:
var bLetter = new createjs.Shape();
bLetter.graphics.append({exec: setPoweredState});
bLetter.graphics.moveTo(0, 0)
.lineTo(0, segSize * 2)
.arc(circSize, segSize * 2, circSize, Math.PI, Math.PI + 0.0001, true);
setPoweredState 函数 - 当我设置bLetter.powered = true 时,线条颜色应该会改变:
setPoweredState = function(ctx, shape) {
if(shape.powered) {
shape.color = consts.COLOR_LINE_ACTIVE;
} else {
shape.color = consts.COLOR_LINE_INACTIVE;
}
shape.graphics.beginStroke(shape.color).setStrokeStyle(consts.STROKE_SIZE, 'round', 'round');
}
当我设置 bLetter.powered = true 并检查 bLetter.color 时,似乎该函数已执行 - bLetter.color 属性发生了变化。但是,画布上的bLetter 对象没有更新。更重要的是,它根本没有绘制 - 可能我以不正确的方式使用append()。我错过了什么?
顺便说一句:我省略了在画布上初始化 createjs.Stage 并添加 bLetter 作为它的孩子的代码,我认为这不是问题,形状绘制正确,只有颜色不会改变。
【问题讨论】:
标签: javascript html canvas createjs easeljs