【问题标题】:Drawing App, How to Erase绘图应用程序,如何擦除
【发布时间】:2014-11-15 05:20:04
【问题描述】:

(我是 AS3 的新手)我在这里找到了一个有用的代码 http://www.flashandmath.com/advanced/smoothdraw/ 我正在尝试创建一个擦除按钮,我正在尝试使用 .cacheAsBitmap = true;但这只有在有掩码的情况下才有效(我在一些 AS2 应用程序上看到了这个,你可以擦除位图然后你可以重绘)。 附言我稍微更改了代码以更改背景,现在 drawBackgroundfunction 看起来像这样:

    function drawBackground():void {
    //We draw a background with a very subtle gradient effect so that the canvas darkens towards the edges.
    var mesh:Shape = new Shape();
    var gradMat:Matrix = new Matrix();
    gradMat.createGradientBox(700,500,0,0,0);
    var bg:Sprite = new Sprite();
    mesh.graphics.beginBitmapFill(new lignes(), null, true, false);
    //bg.graphics.beginGradientFill("radial",[0xDDD0AA,0xC6B689],[1,1],[1,255],gradMat);
    //bg.graphics.drawRect(0,0,700,500);
    //bg.graphics.endFill();
    mesh.graphics.drawRect(0, 0, 700, 500);
    mesh.graphics.endFill();
    boardBitmapData.draw(mesh);
    mesh.cacheAsBitmap = true;
    //We clear out the undo buffer with a copy of just a blank background:
    undoStack = new Vector.<BitmapData>;
    var undoBuffer:BitmapData = new BitmapData(boardWidth, boardHeight, false);
    undoBuffer.copyPixels(boardBitmapData,undoBuffer.rect,new Point(0,0));
    undoStack.push(undoBuffer);
}

我只是想创建一个擦除方法,谢谢你的帮助

编辑:我的意思是只删除被点击的区域

【问题讨论】:

    标签: drawing erase actionscript-3


    【解决方案1】:

    清理形状试试:

    mesh.graphics.clear();
    

    清理 Shape 对象。我不知道您还对 boardBitmapData 变量做了什么,也许还需要做一些事情。

    • clear() - 清除绘制到此 Graphics 对象的图形,并重置填充和线条样式设置。

    【讨论】:

    • 感谢您的回答我会尝试使用它,也许如果我使用相同的功能进行绘制并且使用此功能将起作用,因为无论如何我是在鼠标按下后擦除鼠标移动的区域谢谢
    【解决方案2】:

    您需要将您的画布转换为位图,然后使用蒙版删除或混合模式 ERASE,并再次绘制从蒙版位图创建一个新位图,最后将其用作背景。

    【讨论】:

      猜你喜欢
      • 2014-05-14
      • 2014-04-03
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 2015-05-19
      • 1970-01-01
      • 1970-01-01
      • 2016-04-06
      相关资源
      最近更新 更多