将新的笔触颜色注入到形状中

时间:2015-11-05 00:57:03

标签: javascript createjs easeljs

我有一个绘图画布(基于EaselJS CurveTo example),当我在mouseup时,我想在渲染到画布的形状中注入一种新颜色。我也想在不使用过滤器的情况下这样做。

BIN:https://jsbin.com/qejesuvovu/1/edit?html,output

我曾经直接在形状图形中注入自定义填充/描边,但在更高版本的EaselJS中,这已停止工作。

marker.graphics._dirty = true;
marker.graphics._fill = new createjs.Graphics.Fill('blue');
marker.graphics._stroke = new createjs.Graphics.Stroke('blue');

使用单一笔触颜色动态更改形状颜色的推荐方法是什么?

更新:

在进一步研究之后,我发现我需要能够保持克隆形状的能力,并保留独立改变颜色的功能。

BIN:https://jsbin.com/gorasizuho/edit?html,output

1 个答案:

答案 0 :(得分:2)

在0.7.0版本中,图形被重新设计为使用"命令"。用于绘图的API没有什么不同(除了删除旧的appendInstruction API),但是您可以随时修改各个命令的属性,并且在更新阶段时会反映它们。

var shape = new createjs.Shape();
shape.graphics.setStrokeStyle(3);
var strokeCommand = shape.graphics.beginStroke("#f00").command;
shape.graphics.drawRect(0,0,100,100);

您可以修改任何命令的属性:

strokeCommand.style = "#00f";

您可以在图形文档中看到完整的命令列表。 http://createjs.com/docs/easeljs/classes/Graphics.html#property_command - 每个命令都有单独的文档:http://createjs.com/docs/easeljs/classes/Graphics.Stroke.html

以下是使用命令修改stroke-dash offset和drawRect坐标的示例:http://jsfiddle.net/lannymcnie/gg8sv4cq/

您可以在此处阅读更多内容:http://blog.createjs.com/new-command-approach-to-easeljs-graphics/

相关问题