Reprinted from: http://blog.csdn.net/mad2man/article/details/16898369Category: Cocoa SDK2013-11-23 11:52 388 People read comments (0) favorite reports
Demo function: Based on Caemitterlayer snowflakes, fireworks, flames, love and other effects.
Demo Description: Based on the core animation particle emission system, particles are initialized with Caemittercell. The particles are drawn on the background layer box boundary
Demo screenshot:
Emitterposition: Launch position
Emittersize: The size of the transmitting source;
Emittermode: Launch mode
- NSString * Const kcaemitterlayerpoints;
- NSString * Const Kcaemitterlayeroutline;
- NSString * Const Kcaemitterlayersurface;
- NSString * Const Kcaemitterlayervolume;
Copy code Emittershape: The shape of the emitter source:
- NSString * Const Kcaemitterlayerpoint;
- NSString * Const Kcaemitterlayerline;
- NSString * Const Kcaemitterlayerrectangle;
- NSString * Const kcaemitterlayercuboid;
- NSString * Const kcaemitterlayercircle;
- NSString * Const Kcaemitterlayersphere;
Copy code Rendermode: Render Mode:
- NSString * Const kcaemitterlayerunordered;
- NSString * Const Kcaemitterlayeroldestfirst;
- NSString * Const Kcaemitterlayeroldestlast;
- NSString * Const Kcaemitterlayerbacktofront;
- NSString * Const kcaemitterlayeradditive;
Copy Code properties:
birthrate: particle generation coefficient, default 1.0;
Emittercells: An array of Caemittercell objects that are used to put particles on a layer;
Emitterdepth: Determining the depth of particle shape contact: emitter shape
Emitterzposition: the z-coordinate position of the transmitting source;
Lifetime: Particle life cycle
Preservesdepth: Not much clear (particles are flattened on the layer)
Scale: The scaling ratio of the particles:
Seed: Used to initialize seeds generated by random numbers
Spin: self-rotating speed
Velocity: particle velocity
Caemittercell
Caemittercell the particles emitted from the caemitterlayer; The emitter cell defines the direction of the particle emission.
Alpharange: The extent to which a particle's color alpha can change;
Alphaspeed: The speed at which particle transparency changes over the life cycle;
birthrate: Velocity multiplier factor for particle parameters; number of particles emitted per second
Bluerange: The color of a particle blue can change the range;
Bluespeed: The speed at which particle blue changes over the life cycle;
Color: The colors of the particles
Contents: is a Cgimageref object, both particles to show the picture;
Contentsrect: Should be drawn in the contents of the sub-rectangle:
Emissionlatitude: Angle of the z-axis direction of the launch
The direction of transmission of emissionlongitude:x-y plane
Emissionrange: The angle of the surrounding emission
Emittercells: particles emitted by a particle
Enabled: whether particles are rendered
Greenrange: The color of a particle green can change the range;
Greenspeed: The speed at which particle green changes over the life cycle;
Lifetime: Life cycle
Lifetimerange: Life cycle Range lifetime= lifetime (+/-) Lifetimerange
Magnificationfilter: Not so clear as to increase your size
Minificatonfilter: Reduce your size
Minificationfilterbias: Reducing the size factor
Name: the names of the particles
Redrange: The color of a particle red can change the range;
RedSpeed; The speed at which particle red changes over the life cycle;
Scale: Zoom:
Scalerange: scale scale range;
Scalespeed: Scale speed:
Spin: Sub-rotation angle
Spinrange: Sub-rotation angle range
Style: Not very clear:
Velocity: Velocity
Velocityrange: Speed Range
Xacceleration: Particle x-direction acceleration component
Yacceleration: Acceleration component in Y-direction of particles
Zacceleration: Acceleration component in Z-direction of particles
-(void) viewdidload
{
[Super Viewdidload];
Caemitterlayer *snowemitter = [Caemitterlayer layer];
Snowemitter.emitterposition = Cgpointmake (self.view.bounds.size.width/2.0,-30);
Snowemitter.emittersize = Cgsizemake (self.view.bounds.size.width, 0.0);
Snowemitter.emittermode = Kcaemitterlayeroutline;
Snowemitter.emittershape = Kcaemitterlayerline;
Caemittercell *snowflake = [Caemittercell Emittercell];
snowflake.birthrate = 2.0;
Snowflake.lifetime = 120.0;
snowflake.velocity =-10;
Snowflake.velocityrange = 10;
Snowflake.yacceleration = 2;
Snowflake.emissionrange = 0.5 * M_PI;
Snowflake.spinrange = 0.25 * M_PI;
Snowflake.contents = (ID) [[UIImage imagenamed:@ "Dazflake"] cgimage];
Snowflake.color = [[Uicolor colorwithred:0.600 green:0.658 blue:0.743 alpha:1.000] cgcolor];
Snowemitter.shadowopacity = 1.0;
Snowemitter.shadowradius = 0.0;
Snowemitter.shadowoffset = Cgsizemake (0.0, 1.0);
Snowemitter.shadowcolor = [[Uicolor blackcolor] cgcolor];
Snowemitter.emittercells = [Nsarray arraywithobject:snowflake];
[Self.view.layer Insertsublayer:snowemitter above:0];
Do any additional setup after loading the view.
}