【发布时间】:2016-04-10 20:47:58
【问题描述】:
我开始探索 HTML5 画布,对于我的问题的幼稚,我提前道歉。使用 Flash CC,我生成了一个带有矩形的画布:
(function (lib, img, cjs, ss) {
var p; // shortcut to reference prototypes
// library properties:
lib.properties = {
width: 550,
height: 400,
fps: 24,
color: "#FFFFFF",
manifest: []
};
// symbols:
// stage content:
(lib.canvas_test = function() {
this.initialize();
// Layer 1
this.shape = new cjs.Shape();
this.shape.graphics.beginFill().beginStroke("#669966")
.setStrokeStyle(1,1,1).moveTo(-94,-62).lineTo(94,-62).lineTo(94,62).lineTo(-94,62).closePath();
this.shape.setTransform(198,136);
this.shape_1 = new cjs.Shape();
this.shape_1.graphics.beginFill("#FF933C")
.beginStroke().moveTo(-94,62).lineTo(-94,-62).lineTo(94,-62).lineTo(94,62).closePath();
this.shape_1.setTransform(198,136);
this.addChild(this.shape_1,this.shape);
}).prototype = p = new cjs.Container();
p.nominalBounds = new cjs.Rectangle(378,273,190,126);
})(lib = lib||{}, images = images||{}, createjs = createjs||{}, ss = ss||{});
var lib, images, createjs, ss;
现在我被困住了。如何使用 Javascript 函数检索(和更改)矩形的颜色?我曾希望这些形状只是画布的子对象,但事实似乎并非如此。
【问题讨论】:
-
画布上的东西只是图像数据——它们在任何地方都不作为实际实体存在,您需要自己跟踪它们。也就是说,生成的代码似乎正在使用CreateJS,它似乎可以为您执行一些对象跟踪(即
new cjs.Shape())。
标签: javascript html canvas createjs easeljs