AS位图粒子破碎效果

=。= 最近一直在reloop Miku 的 cat dance. 真的很好听呀。尤其是第一张插图,已经被偶拿来做墙纸了呢。
于是乎,闲着无聊,用AS做成了一个位图粒子破碎效果玩玩,效果还不错的说。
整张位图大小为:477*348 粒子个数:6639 渲染时间: 7秒 渲染机器配置:i5-2430M

整个swf有300+KB,加上渲染时间,请耐心等待个20+秒吧~

[鼠标点击MIKU破碎,键盘任意键拼合]

附:MIKU PV CAT DANCE
源码
PixelsBoom.as
[cc lang=”actionscript3″ nowrap=”false”]
package
{
import com.greensock.TweenLite;
import com.greensock.easing.*;

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.ui.ContextMenu;
import flash.utils.ByteArray;

[SWF(frameRate=”60″,width=”500″,height=”500″)]
public class PixelsBoom extends Sprite
{
[Embed(source=”../sources/miku.png”)]
private var _miku:Class;

private var peaceSize:Number=5;
private var img:Bitmap;
private var container:Sprite=new Sprite();
private var pointArr:Array;
private var peacing:Boolean=false;

public function PixelsBoom()
{
stage?init(null):addEventListener(Event.ADDED_TO_STAGE,init);
}

private function init(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE,init);
var menu:ContextMenu=new ContextMenu();
menu.hideBuiltInItems();
this.contextMenu=menu;

img=new Bitmap(new _miku().bitmapData);
container.x=stage.stageWidth/2-img.width/2;
container.y=stage.stageHeight/2-img.height/2;

addChild(container);

var info:TextField=new TextField();
info.selectable=false;
info.text=”[鼠标单击-粉碎] [键盘任意键-拼合]”;
info.width=info.textWidth+10;
info.x=stage.stageWidth/2-info.width/2;
info.y=stage.stageHeight-30;

addChild(info);

for(var i:int=peaceSize;i=0;i–)
{
var child:Bitmap=container.getChildAt(i) as Bitmap;
TweenLite.to(child,10,{x:Math.random()*stage.stageWidth-stage.stageWidth/2+img.width/2,y:Math.random()*stage.stageHeight-stage.stageHeight/2+img.height/2,alpha:0,ease:Expo.easeInOut,delay:i*0.003});
}
peacing=true;
container.removeEventListener(MouseEvent.CLICK,onpacing);
stage.addEventListener(KeyboardEvent.KEY_DOWN,repeacing);
}

private function repeacing(e:KeyboardEvent):void
{
if(peacing)
{
for(var i:int=container.numChildren-1;i>=0;i–)
{
var child:Bitmap=container.getChildAt(i) as Bitmap;
var tempPoint:Point=pointArr[i] as Point;
TweenLite.to(child,10,{x:tempPoint.x,y:tempPoint.y,alpha:1,delay:(container.numChildren-i)*0.003,ease:Expo.easeInOut});
}
peacing=false;
container.addEventListener(MouseEvent.CLICK,onpacing);
stage.removeEventListener(KeyboardEvent.KEY_DOWN,repeacing);
}
}
}
}
[/cc]

发表评论

电子邮件地址不会被公开。 必填项已用*标注