|
版主
  
- UID
- 1685
- 帖子
- 2853
- 酷币
- 17002 枚
- 威望
- 12 点
- 推广币
- 87 枚
|
1F
大 中
小 发表于 2007-9-17 16:58 只看该作者
【适中】AS编写的雪景
您是第1226位浏览者
AS编写的雪景
贡献一段纯AS编写的雪景代码,不需在场景中建任何实例,只需将以下代码添加到新建的Flash的时间线第1帧中就ok。如有不妥,敬请指正。免费内容:var sceneWidth =550;//画布宽
var sceneHeight=300;//画布高
var sideDisWidth = Stage.width/2-sceneWidth/2;
var sideDisHeight = Stage.height/2-sceneHeight/2;
var snowNum = 80; //雪花数量80,这里可以随意调
var snowSpace:MovieClip = _root.createEmptyMovieClip("room", 1);
function addMasker(){
_root.createEmptyMovieClip("masker", -2);
with (masker) {
lineStyle(1, 0xcccccc, 100);
beginFill(0x000000, 70);
moveTo(sideDisWidth, sideDisHeight);
lineTo(sideDisWidth+sceneWidth, sideDisHeight);
lineTo(sideDisWidth+sceneWidth, sideDisHeight+sceneHeight);
lineTo(sideDisWidth, sideDisHeight+sceneHeight);
lineTo(sideDisWidth, sideDisHeight);
endFill();
}
createSnow();
}
function createSnow() {
var n = 0;
while (n<snowNum) {
var snow:MovieClip = snowSpace.createEmptyMovieClip("s"+n, n);
var radius:Number = Math.random()*3;
drawSnow(snow, radius);
n++;
}
}
function drawSnow(snow:MovieClip, radius:Number) {
var p = radius*.9;
with (snow) {
colors = [0xCCCCCC, 0xFFFFFF];
alphas = [100, 100];
ratios = [0, 255];
matrix = {matrixType:"box", x:-Math.random()*2*radius, y:-Math.random()*2*radius, w : 2*radius, h:2*radius, r: (90/180)*Math.PI};
beginGradientFill("radial", colors, alphas, ratios, matrix);
curveTo(p, -p, radius, 0);
curveTo(p, p, 0, radius);
curveTo(-p, p, -radius, 0);
curveTo(-p, -p, 0, -radius);
endFill();
}
snowProperty(snow, sceneWidth, sceneHeight);
}
function snowProperty(snow, w, h) {
snow._x = sideDisWidth+Math.random()*w;
snow._y = sideDisHeight+Math.random()*h;
snow._rotation = Math.random()*120+30;
snow.stepX = Math.cos((snow._rotation*Math.PI)/180);
snow.stepY = Math.random()*2+1;
setInterval(snowFall, 30, snow);
}
function snowFall(snow) {
snow._x += snow.stepX;
snow._y += snow.stepY;
if (snow._x<sideDisWidth) {
snow._x = sideDisWidth+sceneWidth;
}
if (snow._x>sideDisWidth+sceneWidth) {
snow._x = sideDisWidth;
}
if (snow._y>sideDisHeight+sceneHeight) {
snow._y = sideDisHeight;
}
}
addMasker(); 效果:
http://www.9941.cn/bbs/UploadFile/2007-9/20079818121243252.swf
[ 本帖最后由 justin_h 于 2007-9-17 17:11 编辑 ]
欢迎加入ZCOOL(北京地区)足球群:59662874(不能经常来踢球的朋友,请勿入群!)
|