论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

flash as利用Bitmap特效打造被风吹散效果

文章类别:Flash AS | 发表日期:2009-5-6 8:01:54

  Bitmap特效,被风吹散效果。

详细代码:

  1. package

  2. {

  3. import flash.display.Bitmap;

  4. import flash.display.BitmapData;

  5. import flash.display.MovieClip;

  6. import flash.display.Sprite;

  7. import flash.events.Event;

  8. import flash.filters.BlurFilter;

  9. import flash.geom.Point;

  10. import flash.geom.Rectangle;



  11. /**

  12. * ...

  13. * @author flashk

  14. */

  15. public class Min extends Sprite

  16. {

  17. public var a_mc:MovieClip;



  18. private var bd:BitmapData;

  19. private var bds:BitmapData;

  20. private var ps:Array;



  21. public function Min() {

  22. bd = new BitmapData(1420, 300, true);

  23. bds = new BitmapData(a_mc.width, a_mc.height, true);

  24. bds.draw(a_mc);

  25. var bp:Bitmap = new Bitmap();

  26. bp.bitmapData = bd;

  27. this.addChild(bp);

  28. start();

  29. }

  30. private function start():void {

  31. ps = new Array();

  32. for (var i:int = 1; i <= bds.width; i++) {

  33. for (var j:int = 1; j <= bds.height; j++) {

  34. ps.push(new Po(i, j, bds.getPixel32(i, j),bds.width));

  35. }

  36. }

  37. this.addEventListener(Event.ENTER_FRAME, render);

  38. this.removeChild(a_mc);

  39. }

  40. private function render(event:Event):void {

  41. var po;

  42. //bd.fillRect(new Rectangle(0, 0, bd.width, bd.height), 0);

  43. bd.applyFilter(bd, new Rectangle(0, 0, bd.width, bd.height), new Point(0, 0), new BlurFilter(2, 2, 1));

  44. bd.lock();

  45. var len = ps.length;

  46. for (var i:int = 0 ; i < len; i+=1) {

  47. po = ps[i];

  48. po.move();

  49. bd.setPixel32(po.x, po.y+80, po.color);

  50. }

  51. bd.unlock();

  52. }

  53. }



  54. }

  55. class Po {

  56. public var x:Number;

  57. public var y:Number;

  58. public var color:uint;

  59. private var speed:Number;

  60. private var r:Number = 0;

  61. private var by:Number;



  62. public function Po(x:Number, y:Number, color:uint,w:Number) {

  63. this.x = x;

  64. this.y = y;

  65. this.color = color;

  66. this.speed = Math.random() * 10 - (w - x) / 2;

  67. //r = Math.random() * 50;

  68. this.by = y;

  69. }

  70. public function move():void {

  71. speed += 0.5;

  72. if(speed>0){

  73. this.x += speed;

  74. r += 10;

  75. this.y = this.by + Math.sin(r* Math.PI/180)*50;

  76. }

  77. }

  78. }


源文件和swf下载s2demo.rar

再来玩个加鼠标控制的,美女被风吹散...

  1. package

  2. {

  3. import flash.display.Bitmap;

  4. import flash.display.BitmapData;

  5. import flash.display.MovieClip;

  6. import flash.display.Sprite;

  7. import flash.events.Event;

  8. import flash.filters.BlurFilter;

  9. import flash.filters.ColorMatrixFilter;

  10. import flash.geom.ColorTransform;

  11. import flash.geom.Point;

  12. import flash.geom.Rectangle;



  13. /**

  14. * ...

  15. * @author flashk

  16. */

  17. public class Min extends Sprite

  18. {

  19. public var a_mc:MovieClip;



  20. private var bd:BitmapData;

  21. private var bds:BitmapData;

  22. private var ps:Array;

  23. private var ns:uint;

  24. private var checks:Array;

  25. private var noise:BitmapData;

  26. private var randomSeed:Number;

  27. private var image:BitmapData;

  28. private var rect:Rectangle;

  29. private var cTra:ColorTransform;

  30. private var vectorList:Array;

  31. private var num:uint = 10000;



  32. public function Min() {



  33. noise = new BitmapData(a_mc.width, a_mc.height, false, 0x000000);

  34. randomSeed = Math.floor(Math.random() * 0xFFFF);

  35. noise.perlinNoise(a_mc.width, a_mc.height, 4, randomSeed, false, false, 1 | 2 | 0 | 0 );

  36. image = new BitmapData(465, 465, true, 0);

  37. this.addChild(new Bitmap(image));

  38. rect = new Rectangle( 0, 0, 465, 465 )

  39. cTra = new ColorTransform(1, 1, 1, 0.9, 0, 0, 0, 0)



  40. bd = new BitmapData(600, 450, true);

  41. bds = new BitmapData(a_mc.width, a_mc.height, true,0x00FFFFFF);

  42. bds.draw(a_mc);

  43. var bp:Bitmap = new Bitmap();

  44. bp.bitmapData = bd;

  45. ps = new Array();

  46. start(1);

  47. this.removeChild(a_mc);

  48. }

  49. private function start(s:uint):void {

  50. ns = s;

  51. vectorList = [];

  52. for (var i:int = s; i <= bds.width; i++) {

  53. for (var j:int = 1; j <= bds.height; j++) {

  54. vectorList.push(new Po(i, j, bds.getPixel32(i, j),bds.width,this));

  55. }

  56. }

  57. this.addEventListener(Event.ENTER_FRAME, render);

  58. }

  59. private function render(event:Event):void {

  60. image.colorTransform( rect, cTra );

  61. image.lock();

  62. var len:uint = vectorList.length;

  63. for (var i:uint = 0; i < len; i++) {

  64. var body:Po = vectorList[i];

  65. body.speed += 0.4;

  66. if(body.speed>0){

  67. var col:Number = noise.getPixel(body.px, body.py);

  68. body.ax += ((col >> 16 & 0xFF) - 128)/1000;

  69. body.ay += ((col >> 8 & 0xFF) -128)/1000;



  70. body.vx += body.ax;

  71. body.vy += body.ay;

  72. body.px += body.vx;

  73. body.py += body.vy;



  74. body.ax *= .975;

  75. body.ay *= .975;

  76. body.vx *= .92;

  77. body.vy *= .92;

  78. }

  79. if (body.px < 0) {

  80. vectorList.splice(i, 1);

  81. len -= 1;

  82. }

  83. image.setPixel32( body.px, body.py+100, body.color );

  84. }

  85. image.unlock();

  86. }

  87. }

  88. }

  89. class Po {

  90. public var x:Number;

  91. public var y:Number;

  92. public var color:uint;

  93. public var speed:Number;

  94. private var r:Number = 0;

  95. private var by:Number;

  96. public var vx:Number = 0;

  97. public var vy:Number = 0;

  98. public var ax:Number = 0;

  99. public var ay:Number = 0;

  100. public var px:Number;

  101. public var py:Number;



  102. public function Po(x:Number, y:Number, color:uint,w:Number,eventLis:Object) {

  103. this.x = x;

  104. this.y = y;

  105. this.px = x;

  106. this.py = y;

  107. this.color = color;

  108. this.speed = Math.random() * 15 - (w - x) / 3 -20;

  109. this.by = y;

  110. }

  111. }


鼠标控制swf效果:s2wind-mouseControl.rar

视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058