The realization of snow falling and stacking effect

Source: Internet
Author: User
Tags addchild

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.