【发布时间】:2015-09-25 23:26:53
【问题描述】:
我在使某些功能正常工作时遇到了一些困难。我正在尝试使用easelJS创建橡皮擦并擦除图像的一部分。我见过其他人这样做,但只是擦除其他图形-当我尝试擦除图像时,我什么也做不了。如果我想擦除位图而不是其他图形,这可能吗?
我也尝试使用 AlphaMaskFilter,但它给我的结果与我正在寻找的完全相反(它掩盖了一切,只揭示了我画的东西)。
var c = createjs, stage, art;
var x, y, listener, color, hue=0;
stage = new c.Stage("test");
var testImg = new c.Bitmap("http://lorempixel.com/output/animals-q-c-640-480-5.jpg");
art = stage.addChild(testImg, new c.Shape());
art.cache(0,0,600,400);
stage.on("stagemousedown", startDraw, this);
function startDraw(evt) {
listener = stage.on("stagemousemove", draw, this);
stage.on("stagemouseup", endDraw, this);
color = c.Graphics.getHSL(hue+=85, 50, 50);
x = evt.stageX-0.001; // offset so we draw an initial dot
y = evt.stageY-0.001;
draw(evt); // draw the initial dot
}
function draw(evt) {
art.graphics.ss(20,1).s(color).mt(x,y).lt(evt.stageX, evt.stageY);
// the composite operation is the secret sauce.
// we'll either draw or erase what the user drew.
art.updateCache(erase.checked ? "destination-out" : "source-over");
art.graphics.clear();
x = evt.stageX;
y = evt.stageY;
stage.update();
}
function endDraw(evt) {
stage.off("stagemousemove", listener);
evt.remove();
}
【问题讨论】:
标签: easeljs