粒子动画as3分层



为了获得完美的粒子雪效果,我已经完成了几篇教程。我现在唯一需要做的就是复制粒子效果,并在背景和前景之间播放它的第二个版本。我仍然想保留原来的最上层。我试着把代码包装在一个函数中,并用不同的名称制作其中两个,但我遇到了一堆奇怪的错误。所以,我来这里不是为了破坏我已经拥有的东西,而是为了征求关于这种情况的任何建议。这是我的密码。我正在使用Greenlock动画库来处理我的时间线和动画。

import com.greensock.*;
import com.greensock.easing.*;
addChildAt(MC_BG, 0)
addChildAt(MC_FG, 2)
var tl:TimelineMax=new TimelineMax({paused:false});
function createFlake(offset) {
//create a flake (attach symbol in library with Class flake) and position on stage
var flake:Flake = new Flake();
flake.y=-50;
flake.x=randomRange(-10,1090);
flake.alpha=0;

addChild(flake);
//create timeline for each flake
var nestedTl:TimelineMax = new TimelineMax();
//how much wiggling / zig zagging
var wiggle:Number=randomRange(15,35);
//zig or zag?
wiggle=Math.random() > .5?- wiggle:wiggle;
//how fast and big
var speed:Number=randomRange(5,15);
//fade and grow
nestedTl.insert(TweenMax.to(flake, .5, {alpha:randomRange(.5,1), scaleX:speed, scaleY:speed}));
//go down
nestedTl.insert(TweenMax.to(flake,speed, {y:800}));
//zig zag
nestedTl.insert(TweenMax.to(flake, speed*.15, {x:String(wiggle), repeat:Math.floor(randomRange(1,4)), yoyo:true, ease:Sine.easeInOut}));
tl.insert(nestedTl, offset);
}
//generate random num between a min and max value
function randomRange(min:Number, max:Number):Number {
return min + (Math.random() * (max - min));
}
function init() {
//create a bunch of flakes and add them to timeline
for (var count:Number = 0; count<10000; count++) {
    var offset = count * 0.075;
    createFlake(offset);
}
}
init();

如有任何帮助,我们将不胜感激。

答案太简单了,我完全忽略了它。我制作了3个空白的电影剪辑,在每个剪辑中我都放了一个稍微修改过的代码版本。然后我把每个电影剪辑都放在我想要的和鲍勃的叔叔之间的一层上,效果很好。

最新更新