Source: Http://files.cnblogs.com/flash3d/snow.rar
This is the leader of the work assigned: I want to see snowflakes falling!!
The effect of this, technical nothing new, the effect is beautiful or not mainly to see whether the snow caught in the air feeling.
The effect is to show the feeling of snowflakes in the air mainly from the following aspects:
1. Snow is falling is not a hail drop, so snowflakes in the air will certainly change, in the wind, the snow will be in the air irregular dance (the word good niang. )
Therefore, in the display effect, snowflakes need to get a longitudinal and transverse random rotation force
Ln.rotationx + + math.random () * 10;
Ln.rotationy + + math.random () * 10;
2. Snowflakes exist in space, not on the plane, because the near large and far small, so the snowflakes on the screen can not be as large. When we initialize, we give the snowflake a random scaling.
Ln.scalex = Ln.scaley = Math.random () * 0.3 + 0.1;
3. Due to the near-large and small law, so each snowflake fall must be not as fast (near fast and slow). Look at the plane, he should be proportional to the zoom value.
_INDEXES[LN] = {vy:Math.random () * Ln.scaley * 8 + 4, INIY:LN.Y};
4. Snow landing to slowly accumulate, to the ground will make the ground rise, so to add snow accumulation effect. Here to the ground collision detection is divided into two steps, the first step is coarse detection, snowflakes over the specified range, before the pixel-level detection, improve the efficiency of collision detection, but also ensure the accumulation of snow effect.
If the snowflake arrives at the stack detection height, then detect the stack if
(ln.y >= _plie[int (ln.x)))
{
//If the detection detects that there is no collision and does not cross the bounds, it will accumulate if
(!_ Plieimg.hittest (new point (0, 0), 0, New Point (ln.x, LN.Y)) && LN.Y < stageheight-density) return;
_shut.addchild (LN);//Add to container, then photograph
_plieimg.draw (_shut);
AddChild (LN); add back to the current display object
_plie[int (ln.x)] = ln.y-density < _plie[int (ln.x)]?ln.y-density:_plie[int ( ln.x)];//stack detection height increase
LN.Y = _indexes[ln].iniy;//Initialize y position
ln.x = math.random () * stagewidth;//randomly obtain x position (for snow to accumulate evenly)
}
Other points are commented out in the code, and the source files are on top.
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/