2014-11-14 41 views
0

(我是AS3的新手)我在这里找到了一个有用的代码http://www.flashandmath.com/advanced/smoothdraw/,我试图创建一个Erase按钮,我试图使用.cacheAsBitmap = true;,但只有在有掩码的情况下才能使用(我在某些AS2应用程序中看到了这种情况,可以擦除位图,然后重新绘制)。 P.S.我改变了代码稍微改变背景现在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); 
} 

我只是想创建一个擦除梅索德,感谢您的帮助

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

回答

0

清洁形状尝试:

mesh.graphics.clear(); 

清洁Shape对象。我不知道你还在用boardBitmapData变量做什么,也许还需要做一些事情。

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

感谢您的回答我会尝试使用这个,也许如果我使用相同的功能绘制和使用此功能将工作,因为我是在鼠标移动后删除鼠标移动区域,无论如何感谢 – Rurush

0

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