最后,我们来了!
最近有些延迟,是啊,我最近有很多的工作。
我已经准备了三个演示和发布(但远非完美的并且尚未记录)。的演示是FLA的...你可以找到时间轴代码在这篇文章后半部分和演示。在接下来的日子里,我会发布一些文件,所以直到那时只是看的演示代码unserstand之类的基本使用。
下载闪电类
演示N°1:
该演示展示了两种不同的行为的类可以模仿:放电/或闪电。拖动球或近或远的线圈,看到不同的行为。
演示N°2:
本演示展示的最大长度和maxLengthVary的性能。
将手指靠近插头有连续的电力。带来的手远离插头放电的概率降低。实现最大距离简单地将其关闭。
演示N°3:
这个演示是一个很好的发布延迟的理由
一个漂亮的沙箱能直观的演示(一些)属性。
类的递归,能创造出很多的衰减效果。有一对属性能被传递给子对象的子对象。
例如,如果你设置了childrenMaxCount = 6为主要闪电,它有一个最大的6个直接子对象。它的子对象们将有一个childrenMaxCount值依赖的的主实例childrenMaxCount和childrenMaxCountDecay。
所以,如果你设置childrenMaxCount = 6,childrenMaxCountDecay = 0.5子对象们的主实例将有childrenMaxCount的= 3。
如果设置childrenMaxCount = 6,childrenMaxCountDecay = 0时,子对象们的主实例将有childrenMaxCount的的= 6(无衰减)。
此值可以是非常有用的,优化的执行速度会导致更小的分支并不需要很多的子对象或多个步骤的细节。
好吧,我太累了,写了这么多。在接下来的日子里,我会发布一些文件。
演示的代码后休息。等待您的意见,我会在FatCow的网站,看看他们有什么好的托管计划。
演示代码仅仅是时间安排代码实例和试点的闪电类,很邋遢!请不要责怪
演示N°1:
- import com.oaxoa.fx.Lightning;
- import com.oaxoa.fx.LightningFadeType;
- const cx:uint=360;
- const cy:uint=320;
- var color:uint=0xffffff;
- var ll:Lightning=new Lightning(color, 2);
- ll.blendMode=BlendMode.ADD;
- ll.childrenDetachedEnd=true;
- ll.childrenLifeSpanMin=.1;
- ll.childrenLifeSpanMax=2;
- ll.childrenMaxCount=4;
- ll.childrenMaxCountDecay=.5;
- ll.steps=150;
- ll.alphaFadeType=LightningFadeType.TIP_TO_END;
- ball.useHandCursor=ball.buttonMode=true;
- dot1.mouseEnabled=dot2.mouseEnabled=false;
- dot1.alpha=.75;
- var glow:GlowFilter=new GlowFilter();
- glow.color=color;
- glow.strength=3.5;
- glow.quality=3;
- glow.blurX=glow.blurY=10;
- ll.filters=dot1.filters=dot2.filters=[glow];
- addChild(ll);
- ll.childrenProbability=.3;
- var p:Point=new Point();
- randomizePoint();
- function randomizePoint():void {
- var angle:Number=-Math.random()*Math.PI;
- var dist:Number=160+Math.random()*180;
- p.x=cx+Math.cos(angle)*dist;
- p.y=cy+Math.sin(angle)*dist;
- }
- addEventListener(Event.ENTER_FRAME, onframe);
- function onframe(event:Event):void {
- var rnd:Number=Math.random();
- if(rnd<.05) randomizePoint();
- var dx:Number=cx-ball.x;
- var dy:Number=cy-ball.y;
- var d:Number=Math.sqrt(dx*dx+dy*dy);
- if(d<310) {
- dot2.visible=true;
- if(ll.childrenDetachedEnd) {
- ll.childrenDetachedEnd=false;
- ll.alphaFadeType=LightningFadeType.GENERATION;
- ll.killAllChildren();
- }
- ll.endX=dot2.x=ball.x;
- ll.endY=dot2.y=ball.y;
- } else {
- dot2.visible=false;
- if(!ll.childrenDetachedEnd) {
- ll.childrenDetachedEnd=true;
- ll.alphaFadeType=LightningFadeType.TIP_TO_END;
- ll.killAllChildren();
- }
- ll.endX=p.x;
- ll.endY=p.y;
- }
- var ddx:Number=cx-ll.endX;
- var ddy:Number=cy-ll.endY;
- var aangle:Number=Math.atan2(ddy, ddx);
- ll.startX=cx-Math.cos(aangle)*80;
- dot1.scaleX=Math.sin(aangle);
- ll.startY=cy;
- dot1.x=ll.startX;
- dot1.y=ll.startY;
- ll.update();
- }
- ball.addEventListener(MouseEvent.MOUSE_DOWN, onmdown);
- function onmdown(event:MouseEvent):void {
- ball.startDrag();
- }
- ball.addEventListener(MouseEvent.MOUSE_UP, onmup);
- function onmup(event:MouseEvent):void {
- ball.stopDrag();
- }
演示N°2:
- import com.oaxoa.fx.Lightning;
- import com.oaxoa.fx.LightningFadeType;
- setChildIndex(fingers, 2);
- var iy:Number=fingers.y;
- addEventListener(MouseEvent.MOUSE_MOVE, onmove);
- fingers.x=fingers.y/2.5-10;
- function updatePositions():void {
- ll.endX=fingers.x+fingers.dot1.x;
- ll.endY=fingers.y+fingers.dot1.y;
- ll2.endX=fingers.x+fingers.dot2.x;
- ll2.endY=fingers.y+fingers.dot2.y;
- }
- function onmove(event:MouseEvent):void {
- fingers.y=mouseY-150;
- if(fingers.y320) fingers.y=320;
- fingers.x=fingers.y/2.5-10;
- updatePositions();
- event.updateAfterEvent();
- }
- addEventListener(Event.ENTER_FRAME, onframe);
- function onframe(event:Event):void {
- ll.update();
- ll2.update();
- }
- var color:uint=0xddeeff;
- var ll:Lightning=new Lightning(color, 2);
- var ll2:Lightning=new Lightning(color, 2);
- ll.blendMode=ll2.blendMode=BlendMode.ADD;
- ll.childrenProbability=ll2.childrenProbability=.5;
- ll.childrenLifeSpanMin=ll2.childrenLifeSpanMin=.1;
- ll.childrenLifeSpanMax=ll2.childrenLifeSpanMax=2;
- ll.maxLength=ll2.maxLength=50;
- ll.maxLengthVary=ll2.maxLengthVary=200;
- ll.startX=dot3.x;
- ll.startY=dot3.y;
- ll2.startX=dot4.x;
- ll2.startY=dot4.y;
- var glow:GlowFilter=new GlowFilter();
- glow.color=color;
- glow.strength=3.5;
- glow.quality=3;
- glow.blurX=glow.blurY=10;
- ll.filters=ll2.filters=[glow];
- addChild(ll);
- addChild(ll2);
- updatePositions();
演示N°3:
(一堆随机的代码行书面,非常丑陋)
- import com.oaxoa.fx.Lightning;
- import com.oaxoa.fx.LightningFadeType;
- import com.oaxoa.components.ToolTip;
- import fl.controls.Button;
- import fl.data.DataProvider;
- import fl.events.SliderEvent;
- var color:uint=0xffffff;
- var ll:Lightning=new Lightning(color, 2);
- ll.blendMode=BlendMode.ADD;
- var glow:GlowFilter=new GlowFilter();
- glow.color=color;
- glow.strength=4;
- glow.quality=3;
- glow.blurX=glow.blurY=10;
- ll.filters=[glow];
- addChild(ll);
- ll.startX=cross1.x;
- ll.startY=cross1.y;
- ll.endX=cross2.x;
- ll.endY=cross2.y;
- setChildIndex(ll,0);
- ll.childrenMaxGenerations=3;
- ll.childrenMaxCountDecay=.5;
- addEventListener(Event.ENTER_FRAME, onframe);
- function onframe(event:Event):void {
- ll.startX=cross1.x;
- ll.startY=cross1.y;
- ll.endX=cross2.x;
- ll.endY=cross2.y;
- ll.update();
- updateCircles();
- }
- import com.oaxoa.components.FrameRater;
- var fr:FrameRater=new FrameRater(0xffffff, true);
- addChild(fr);
- var ttip:ToolTip=new ToolTip();
- addChild(ttip);
- var tfmt:TextFormat=new TextFormat("_sans", 11, 0xffffff);
- cb0.addItem({label:"Choose a preset", value:0});
- cb0.addItem({label:"Fast discharge", value:1});
- cb0.addItem({label:"Fast discharge (Max length + max length variation)", value:2});
- cb0.addItem({label:"Fast discharge (slow-motion)", value:3});
- cb0.addItem({label:"Moving Thunderbolt", value:4});
- cb0.addItem({label:"Moving Thunderbolt (Max length + max length variation)", value:5});
- cb0.selectedIndex=0;
- cb0.addEventListener(Event.CHANGE, oncb);
- cb0.textField.setStyle("textFormat", tfmt);
- cb0.dropdown.setRendererStyle("textFormat", tfmt);
- cb1.addItem({label:"Discharge", value:false});
- cb1.addItem({label:"Lightning (detached end)", value:true});
- cb1.selectedIndex=1;
- cb1.addEventListener(Event.CHANGE, oncb);
- cb1.textField.setStyle("textFormat", tfmt);
- cb1.dropdown.setRendererStyle("textFormat", tfmt);
- cb2.addItem({label:"None", value:LightningFadeType.NONE});
- cb2.addItem({label:"Generation", value:LightningFadeType.GENERATION});
- cb2.addItem({label:"Tip to end", value:LightningFadeType.TIP_TO_END});
- cb2.selectedIndex=2;
- cb2.addEventListener(Event.CHANGE, oncb);
- cb2.textField.setStyle("textFormat", tfmt);
- cb2.dropdown.setRendererStyle("textFormat", tfmt);
- cb3.addItem({label:"None", value:LightningFadeType.NONE});
- cb3.addItem({label:"Generation", value:LightningFadeType.GENERATION});
- cb3.addItem({label:"Tip to end", value:LightningFadeType.TIP_TO_END});
- cb3.selectedIndex=2;
- cb3.addEventListener(Event.CHANGE, oncb);
- cb3.textField.setStyle("textFormat", tfmt);
- cb3.dropdown.setRendererStyle("textFormat", tfmt);
- function oncb(event:Event):void {
- var t:ComboBox=event.currentTarget as ComboBox;
- switch(t) {
- case cb0:
- setPreset(t.selectedItem.value);
- break;
- case cb1:
- ll.childrenDetachedEnd=t.selectedItem.value;
- ll.killAllChildren();
- break;
- case cb2:
- ll.alphaFadeType=t.selectedItem.value;
- ll.killAllChildren();
- break;
- case cb3:
- ll.thicknessFadeType=t.selectedItem.value;
- ll.killAllChildren();
- break;
- }
- }
- slider.addEventListener(SliderEvent.CHANGE, onslider);
- slider2.addEventListener(SliderEvent.CHANGE, onslider);
- slider3.addEventListener(SliderEvent.CHANGE, onslider);
- slider4.addEventListener(SliderEvent.CHANGE, onslider);
- slider5.addEventListener(SliderEvent.CHANGE, onslider);
- slider6.addEventListener(SliderEvent.CHANGE, onslider);
- slider7.addEventListener(SliderEvent.CHANGE, onslider);
- slider8.addEventListener(SliderEvent.CHANGE, onslider);
- slider9.addEventListener(SliderEvent.CHANGE, onslider);
- slider10.addEventListener(SliderEvent.CHANGE, onslider);
- slider11.addEventListener(SliderEvent.CHANGE, onslider);
- slider12.addEventListener(SliderEvent.CHANGE, onslider);
- slider13.addEventListener(SliderEvent.CHANGE, onslider);
- function onslider(event:SliderEvent):void {
- var t:Slider=event.currentTarget as Slider;
- ttip.show(t.value.toString());
- ttip.y=t.y-30;
- switch(t) {
- case slider:
- ll.smoothPercentage=t.value;
- break;
- case slider2:
- ll.childrenAngleVariation=t.value;
- break;
- case slider3:
- ll.childrenMaxCount=t.value;
- break;
- case slider4:
- ll.wavelength=t.value;
- break;
- case slider5:
- ll.amplitude=t.value;
- break;
- case slider6:
- ll.speed=t.value;
- break;
- case slider7:
- ll.thickness=t.value;
- ll.killAllChildren();
- break;
- case slider8:
- ll.maxLength=t.value;
- break;
- case slider9:
- ll.maxLengthVary=t.value;
- break;
- case slider10:
- ll.childrenProbability=t.value;
- ll.killAllChildren();
- break;
- case slider11:
- ll.childrenLifeSpanMin=t.value;
- ll.killAllChildren();
- if(t.value>slider12.value) slider12.value=t.value;
- break;
- case slider12:
- ll.childrenLifeSpanMax=t.value;
- ll.killAllChildren();
- slider11.visible=t.value!=0;
- break;
- case slider13:
- ll.steps=t.value;
- ll.killAllChildren();
- break;
- }
- ll.render();
- }
- function setPreset(n:uint):void {
- switch(n) {
- // fast discharge
- case 1:
- ll.childrenLifeSpanMin=1;
- ll.childrenLifeSpanMax=3;
- ll.childrenProbability=1;
- ll.childrenMaxGenerations=3;
- ll.childrenMaxCount=4;
- ll.childrenAngleVariation=110;
- ll.thickness=2;
- ll.steps=100;
- ll.smoothPercentage=50;
- ll.wavelength=.3;
- ll.amplitude=.5;
- ll.speed=.7;
- ll.maxLength=0;
- ll.maxLengthVary=0;
- ll.childrenDetachedEnd=false;
- cb1.selectedIndex=0;
- ll.alphaFadeType=LightningFadeType.GENERATION;
- cb2.selectedIndex=1;
- ll.thicknessFadeType=LightningFadeType.NONE;
- cb3.selectedIndex=0;
- break;
- // fast discharge (with max length+variation)
- case 2:
- ll.childrenLifeSpanMin=1;
- ll.childrenLifeSpanMax=3;
- ll.childrenProbability=1;
- ll.childrenMaxGenerations=3;
- ll.childrenMaxCount=4;
- ll.childrenAngleVariation=110;
- ll.thickness=2;
- ll.steps=100;
- ll.smoothPercentage=50;
- ll.wavelength=.3;
- ll.amplitude=.5;
- ll.speed=.7;
- ll.maxLength=440;
- ll.maxLengthVary=75;
- ll.childrenDetachedEnd=false;
- cb1.selectedIndex=0;
- ll.alphaFadeType=LightningFadeType.GENERATION;
- cb2.selectedIndex=1;
- ll.thicknessFadeType=LightningFadeType.NONE;
- cb3.selectedIndex=0;
- break;
- // fast discharge slowmo
- case 3:
- ll.childrenLifeSpanMin=1;
- ll.childrenLifeSpanMax=3;
- ll.childrenProbability=1;
- ll.childrenMaxGenerations=3;
- ll.childrenMaxCount=4;
- ll.childrenAngleVariation=110;
- ll.thickness=2;
- ll.steps=100;
- ll.smoothPercentage=50;
- ll.wavelength=.3;
- ll.amplitude=.5;
- ll.speed=.1;
- ll.maxLength=0;
- ll.maxLengthVary=0;
- ll.childrenDetachedEnd=false;
- cb1.selectedIndex=0;
- ll.alphaFadeType=LightningFadeType.GENERATION;
- cb2.selectedIndex=1;
- ll.thicknessFadeType=LightningFadeType.NONE;
- cb3.selectedIndex=0;
- break;
- // moving thumnder
- case 4:
- ll.childrenLifeSpanMin=.1;
- ll.childrenLifeSpanMax=2;
- ll.childrenProbability=1;
- ll.childrenMaxGenerations=3;
- ll.childrenMaxCount=4;
- ll.childrenAngleVariation=130;
- ll.thickness=3;
- ll.steps=100;
- ll.smoothPercentage=50;
- ll.wavelength=.3;
- ll.amplitude=.5;
- ll.speed=1;
- ll.maxLength=0;
- ll.maxLengthVary=0;
- ll.childrenDetachedEnd=true;
- cb1.selectedIndex=1;
- ll.alphaFadeType=LightningFadeType.TIP_TO_END;
- cb2.selectedIndex=2;
- ll.thicknessFadeType=LightningFadeType.GENERATION;
- cb3.selectedIndex=1;
- break;
- case 5:
- ll.childrenLifeSpanMin=.1;
- ll.childrenLifeSpanMax=2;
- ll.childrenProbability=1;
- ll.childrenMaxGenerations=3;
- ll.childrenMaxCount=4;
- ll.childrenAngleVariation=130;
- ll.thickness=3;
- ll.steps=100;
- ll.smoothPercentage=50;
- ll.wavelength=.3;
- ll.amplitude=.5;
- ll.speed=1;
- ll.maxLength=440;
- ll.maxLengthVary=75;
- ll.childrenDetachedEnd=true;
- cb1.selectedIndex=1;
- ll.alphaFadeType=LightningFadeType.TIP_TO_END;
- cb2.selectedIndex=2;
- ll.thicknessFadeType=LightningFadeType.GENERATION;
- cb3.selectedIndex=1;
- break;
- }
- ll.killAllChildren();
- updateSliders();
- }
- function updateSliders():void {
- slider.value=ll.smoothPercentage;
- slider2.value=ll.childrenAngleVariation;
- slider3.value=ll.childrenMaxCount;
- slider4.value=ll.wavelength;
- slider5.value=ll.amplitude;
- slider6.value=ll.speed;
- slider7.value=ll.thickness;
- slider8.value=ll.maxLength;
- slider9.value=ll.maxLengthVary;
- slider10.value=ll.childrenProbability;
- slider11.value=ll.childrenLifeSpanMin;
- slider12.value=ll.childrenLifeSpanMax;
- slider13.value=ll.steps;
- }
- ///////////////////
- var tf:TextFormat=new TextFormat();
- tf.color=0xffffff;
- cross1.addEventListener(MouseEvent.MOUSE_UP, onup);
- cross1.addEventListener(MouseEvent.MOUSE_DOWN, ondown);
- cross2.addEventListener(MouseEvent.MOUSE_UP, onup);
- cross2.addEventListener(MouseEvent.MOUSE_DOWN, ondown);
- cross1.buttonMode=cross2.buttonMode=cross1.useHandCursor=cross2.useHandCursor=true;
- function ondown(event:MouseEvent):void {
- event.currentTarget.alpha=.2;
- event.currentTarget.startDrag();
- }
- function onup(event:MouseEvent):void {
- event.currentTarget.alpha=1;
- event.currentTarget.stopDrag();
- }
- var circles:Shape=new Shape();
- addChildAt(circles, 0);
- function updateCircles():void {
- circles.graphics.clear();
- if(ll.maxLength>0) {
- circles.graphics.lineStyle(6, 0xffffff, .3);
- circles.graphics.drawCircle(cross1.x, cross1.y, ll.maxLength);
- circles.graphics.lineStyle(2, 0xffffff, .4);
- circles.graphics.drawCircle(cross1.x, cross1.y, ll.maxLength+ll.maxLengthVary);
- var steps:uint=5;
- for(var i:uint=1; i
原文链接:http://blog.oaxoa.com/2009/07/27/actionscript-3-as3-lightning-thunderbolt-electric-discharge-class/
翻译词数:500