我想用flash简单制作一下下雪的场景

2025-01-20 02:59:29
推荐回答(4个)
回答1:

我教你个方法,非常简单。我已经试过了,可以用!
1.第一个图层,放置你的背景图片或着把背景色调成黑色,因为雪花是白的,白色背景你看不出来。
2.新建图层2,点击第一帧,按F9,复制以下代码。
fallSnow(this, 100, [550, 400]);
function fallSnow(path, num, size) {
for (var i = 0; i path.createEmptyMovieClip("s"+i, i);
var mc = path["s"+i];
mc._x = random(size[0]);
mc._y = random(size[1]);
mc.ro = [1, -1][random(2)];
mc.xtime = random(20);
mc.startTime = 0;
mc.id = Math.pow(i, 1/2);
createSnow(mc, mc.id/2.5, "0xffffff", 20*mc.id);
}
var loop = function () {
updateAfterEvent();
for (var i = 0; i var mc = path["s"+i];
mc._rotation += mc.ro*5;
mc._x += mc.id*mc.ro/10;
mc._y += mc.id/2;
mc.startTime++;
scanTar(mc);
scanEdge(mc, size);
}
};
var interval = setInterval(loop, 10);
}
function createSnow(mc, radius, c, alpha) {
with (mc) {
moveTo(0, -radius);
beginFill(c, alpha);
lineStyle(0, "0x000000", 0);
for (var i = 1; i<=6; i++) {
var a1 = -Math.PI/6+i*Math.PI/3;
var a2 = i*Math.PI/3;
lineTo((radius/5)*Math.sin(a1), -(radius/5)*Math.cos(a1));
lineTo(radius*Math.sin(a2), -radius*Math.cos(a2));
}
endFill();
}
}
function scanTar(mc) {
if (mc.startTime>=mc.xtime) {
mc.startTime = 0;
mc.xtime = random(20);
mc.ro = [1, -1][random(2)];
}
}
function scanEdge(mc, size) {
if (mc._x>size[0]) {
mc._x = 0;
} else if (mc._x<0) {
mc._x = size[0];
}
if (mc._y>size[1]) {
mc._y = 0;
}
}
3.保存,测试播放!(这个代码不需要做什么元件,代码自动生成雪花的形状)

回答2:

打开flash(这是AS2.0,flash8和flash mx2004可用,cs版本请选择AS2.0脚本),直接把下面的代码放到第一帧即可,其他的事情都不用做.
stop();
Stage.showMenu = false;
var sceneWidth=550; //舞台宽,可以自己根据舞台大小调整.
var sceneHeight=400; //舞台高,可以自己根据舞台大小调整.
var sideDisWidth = Stage.width/2-sceneWidth/2;
var sideDisHeight = Stage.height/2-sceneHeight/2;
var snowNum = 150; //雪花数量,可以自己调整
var snowSpace:MovieClip = _root.createEmptyMovieClip("room", 1); function addMasker() {
_root.createEmptyMovieClip("masker", -2);
createSnow();
}

function createSnow() {
var n = 0;
while (n 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*.8;
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._xsnow._x = sideDisWidth+sceneWidth;
}
if (snow._x>sideDisWidth+sceneWidth) {

snow._x = sideDisWidth;
}
if (snow._y>sideDisHeight+sceneHeight) {
snow._y = sideDisHeight;
}
}
addMasker();

回答3:

function fallSnow(path, num, size)
{
for (var _loc2 = 0; _loc2 < num; ++_loc2)
{
path.createEmptyMovieClip("s" + _loc2, _loc2);
var _loc1 = path["s" + _loc2];
_loc1._x = random(size[0]);
_loc1._y = random(size[1]);
_loc1.ro = [1, -1][random(2)];
_loc1.xtime = random(20);
_loc1.startTime = 0;
_loc1.id = Math.pow(_loc2, 5.000000E-001);
createSnow(_loc1, _loc1.id / 2.500000E+000, "0xffffff", 20 * _loc1.id);
} // end of for
var _loc3 = function ()
{
updateAfterEvent();
for (var _loc2 = 0; _loc2 < num; ++_loc2)
{
var _loc1 = path["s" + _loc2];
_loc1._rotation = _loc1._rotation + _loc1.ro * 5;
_loc1._x = _loc1._x + _loc1.id * _loc1.ro / 10;
_loc1._y = _loc1._y + _loc1.id / 2;
++_loc1.startTime;
scanTar(_loc1);
scanEdge(_loc1, size);
} // end of for
};
var _loc4 = setInterval(_loc3, 10);
} // End of the function
function createSnow(mc, radius, c, alpha)
{
with (mc)
{
moveTo(0, -radius);
beginFill(c, alpha);
lineStyle(0, "0x000000", 0);
var i = 1;
while (i <= 6)
{
var a1 = -5.235988E-001 + i * 3.141593E+000 / 3;
var a2 = i * 3.141593E+000 / 3;
lineTo(radius / 5 * Math.sin(a1), -radius / 5 * Math.cos(a1));
lineTo(radius * Math.sin(a2), -radius * Math.cos(a2));
++i;
} // end while
endFill();
} // End of with
} // End of the function
function scanTar(mc)
{
if (mc.startTime >= mc.xtime)
{
mc.startTime = 0;
mc.xtime = random(20);
mc.ro = [1, -1][random(2)];
} // end if
} // End of the function
function scanEdge(mc, size)
{
if (mc._x > size[0])
{
mc._x = 0;
}
else if (mc._x < 0)
{
mc._x = size[0];
} // end else if
if (mc._y > size[1])
{
mc._y = 0;
} // end if
} // End of the function
fallSnow(this,100,[1024, 590]);
这是雪花代码

回答4:

as对于新手来说做一些简单的 比如说下雨下雪的东西不太适合
也有不用as的简单方法 先做一两个雪花下落的图形元件 然后打开库 不停的从库里把那个单独的雪花下落的元件拖到场景中 就可以了