Flash中如何制作出逼真的水波纹效果
以下是整理的关于在Flash中如何制作逼真的水波纹效果的步骤。
打开后用在画面上单击鼠标,或按住鼠标左键不放在画面上划过就会出现圈圈涟漪和波纹,非常美丽,跟真的水面一样,非常漂亮。
一、设置舞台大小(256×256)。
二、导入图片到库。不要导入到舞台。
三、打开库设置图片链接。标识符为:surface。将“为运行时导入”勾去掉,勾上“为actionscript 导出”和“在第一帧导出”
四、在第一帧插入动作代码。
var damper = new flash.display.BitmapData(128, 128, false, 128);
var result = new flash.display.BitmapData(128, 128, false, 128);
var result2 = new flash.display.BitmapData(256, 256, false, 128);
var source = new flash.display.BitmapData(128, 128, false, 128);
var buffer = new flash.display.BitmapData(128, 128, false, 128);
var output = new flash.display.BitmapData(256, 256, true, 128);
var surface = flash.display.BitmapData.loadBitmap("surface");
var bounds = new flash.geom.Rectangle(0, 0, 128, 128);
var origin = new flash.geom.Point();
var matrix = new flash.geom.Matrix();
var matrix2 = new flash.geom.Matrix();
matrix2.a = matrix2.d = 2;
var wave = new flash.filters.ConvolutionFilter(3, 3, [1, 1, 1, 1, 1, 1, 1, 1, 1], 9, 0);
var damp = new flash.geom.ColorTransform(0, 0, 9.960937E-001, 1, 0, 0, 2, 0);
var water = new flash.filters.DisplacementMapFilter(result2, origin, 4, 4, 48, 48, "ignore");
attachBitmap(output, 0);
var ms = getTimer();
var frame = 0;
var mouseDown = false;
onMouseDown = function ()
{
mouseDown = true;
};
onMouseUp = function ()
{
onEnterFrame();
mouseDown = false;
};
onEnterFrame = function ()
{
if (mouseDown)
{
var _loc2 = _xmouse / 2;
var _loc1 = _ymouse / 2;
source.setPixel(_loc2 + 1, _loc1, 16777215);
source.setPixel(_loc2 - 1, _loc1, 16777215);
source.setPixel(_loc2, _loc1 + 1, 16777215);
source.setPixel(_loc2, _loc1 - 1, 16777215);
source.setPixel(_loc2, _loc1, 16777215);
} // end if
result.applyFilter(source, bounds, origin, wave);
result.draw(result, matrix, null, "add");
result.draw(buffer, matrix, null, "difference");
result.draw(result, matrix, damp);
result2.draw(result, matrix2, null, null, null, true);
output.applyFilter(surface, new flash.geom.Rectangle(0, 0, 256, 256), origin, water);
buffer = source;
source = result.clone();
};
五、测试看看。点击flash,会一出现圈圈涟漪,效果非常真实。
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |