Flash教程:互动的橡皮刷

2019-10-08 19:57:09于丽

erase_bit.draw(mc1);
redraw_bit.draw(mc1);
//交换erase_bit r通道和a通道数值 所以a通道数值为00
erase_bit.copyChannel(erase_bit, erase_bit.rectangle, new Point(0, 0), 1, 8);
//保存当前使用的工具
var tools:String;
//点击笔刷工具
mc_bursh.onRelease = function()
{
this.gotoAndStop(2);
mc_earse.gotoAndStop(1);
tools = "bursh";
};
//点击橡皮刷工具
mc_earse.onRelease = function()
{
this.gotoAndStop(2);
mc_bursh.gotoAndStop(1);
tools = "easre";
};
//在draw_bit上涂鸦
draw_mc.onPress = function()
{
trace(tools);
if (tools == "bursh")
{
this.onMouseMove = bursh_pic;
}
if (tools == "easre")
{
this.onMouseMove = earse_pic;
}
};
//停止涂鸦
draw_mc.onRelease = function()
{
delete this.onMouseMove;
};
//橡皮刷工具
function earse_pic()
{
var now_rect:Rectangle = new Rectangle(_xmouse, _ymouse, _xmouse base_rectangle.width, _ymouse base_rectangle.height);
trace(now_rect);
//在draw_bit上使用copyPixels alpha为false 透明区域透明 不透明区域保持原色
draw_bit.copyPixels(draw_bit, now_rect, new Point(_xmouse, _ymouse), erase_bit, new Point(0, 0), false);
updateAfterEvent();
}
//笔刷工具
function bursh_pic()
{
var now_rect:Rectangle = new Rectangle(_xmouse, _ymouse, _xmouse base_rectangle.width, _ymouse base_rectangle.height);
trace(now_rect);
//在org_bit上使用copyPixels alpha为true 则笔刷工具只有不透明的地方起作用
draw_bit.copyPixels(org_bit, now_rect, new Point(_xmouse, _ymouse), redraw_bit, new Point(0, 0), true);
updateAfterEvent();
}
//移动背景图观察效果
mc.onPress = function()
{
this.startDrag();
};
mc.onRelease = function()
{
this.stopDrag();
};