First, the system analysis
In Uikit, the particle system consists of two parts:
· One or more caemittercells: The transmitter battery can be viewed as a prototype of a single particle (e.g., a single puff in a cloud of smoke). When a particle is emitted, the uikit creates a random particle based on the emission particle and the definition. This prototype includes properties to control the particle's picture, color, direction, motion, scaling, and life cycle.
· One or more caemitterlayers, but usually only one: this emitting layer mainly controls the shape of the particle (for example, a point, rectangle or circle) and the location of the launch (for example, within the rectangle, or edge). This layer has a global multiplier that can be applied to the caemittercells within the system. These give you a simple way to cover all the changes in the particles. For example, an artificial example will change the X rain to simulate the speed of the wind.
The basics are simple, but these parameters are quite subtle. Caemitterlayer has more than 30 different parameters for custom particle behavior. Below, I'll spell out some special questions
Ii. Non-measurable
1. What makes a particle system a random system?
Caemittercell properties typically have two parameters: a mean value and a "cone", such as velocity and velocityrange.
By default, this "cone" is 0, which means that all particles will have the same speed. By changing the "cone", each emitted particle is randomly disturbed to obtain a value in this "cone" range. This is in Apple's official document Caemitterlayer documentation: there are explanations:
Each layer has it ownrandom number generator state. Emitter cell properties that are defined as Amean and a range, such as a cell ' s speed, the value of the properties areunif Ormly distributed in the interval [M-R/2, M + R/2].
2, the direction of the launch
Caemittercells has a velocity (velocity) attribute, which means the speed of the sending direction. In fact, the direction of this launch is defined by the Emissionlongitude attribute. Apple explains this:
The emission longitude is theorientation to the emission angle in the Xy-plane. It is also often referred toas the azimuth.
Third, the Code
-(void) viewdidload {[Super viewdidload];
Caemitterlayer *emitterlayer = [Caemitterlayer layer];
Emitterlayer.emitterposition = Self.view.center;
_emitterlayer = Emitterlayer;
[Self.view.layer Addsublayer:emitterlayer];
Caemittercell *funnyemittercell = [Caemittercell Emittercell]; Funnyemittercell.contents = (ID) [UIImage imagenamed:@ "Funny.jpg"].
Cgimage;
Funnyemittercell.birthrate = 10.0;
funnyemittercell.velocity = 200.0;
Funnyemittercell.lifetime = 5.0;
Funnyemittercell.scale = 0.1;
Funnyemittercell.name = @ "funny";
Emitterlayer.emittercells = [Nsarray Arraywithobject:funnyemittercell];
[Self bumpangle];
Uilabel *anglelabel = [[Uilabel alloc] Initwithframe:cgrectmake (20, 20, 100, 30)];
Anglelabel.backgroundcolor = [Uicolor Clearcolor];
[Self.view Addsubview:anglelabel];
_anglelabel = Anglelabel; }-(void) Bumpangle {nsnumber *emissionlongitude = [_emitterlayer valueforkeypath:@] EmitterCells.funny.emissionLong
Itude "]; NSNumber*nextlongitude = [NSNumber numberwithfloat:[emissionlongitude Floatvalue] + 0.02];
[_emitterlayer setvalue:nextlongitude forkeypath:@ "EmitterCells.funny.emissionLongitude"];
_anglelabel.text = [NSString stringwithformat:@ "%.0f degrees", [Nextlongitude floatvalue] * 180/M_PI];
[Self performselector: @selector (bumpangle) Withobject:nil afterdelay:0.1];
}
Code Setup/Structure Description:
1, Caemittercell
Caemittercell *effectcell = [Caemittercell Emittercell];
Effectcell several important attributes:
1). birthrate as the name implies that there is no effectcell, this must be set, the specific meaning of a point per second generated Effectcell number
2. Lifetime & Lifetimerange Indicates how long the Effectcell life cycle will be displayed on the screen.
3). Contents this is the same as Calayer, just to set up the picture
4). Name this is used to identify the Caeemitter emittercells in the presence of Effectcell. It's more useful to use SetValue forkeypath.
5. Velocity & Velocityrange & Emissionrange indicates the speed at which the cell is flying to the right of the screen & to the right what range of Flight & +-angle Spread
6). Put the cell into an array and put it in the caeemitter.emittercells. Caeemitter.rendermode has a very good effect, can become a fire is kcaemitterlayeradditive
Property:
Alpharange: The range by which the color alpha of a particle can change;
Alphaspeed: The rate of change of particle transparency in the life cycle;
birthrate: Velocity multiplier factor of particle parameters;
Bluerange: The color of a particle blue can change the range;
Bluespeed: The speed at which particle blue changes in the life cycle;
Color: The colour of a particle
Contents: is a Cgimageref object, both particles to show the picture;
Contentsrect: The son rectangle should be drawn in contents:
Emissionlatitude: Angle of the direction of the z-axis of the launch
Launch direction of Emissionlongitude:x-y plane
Emissionrange; The angle of the surrounding launch
Emittercells: particle emitted by particles
Enabled: Whether the particle is rendered
Greenrange: The color of a particle green can change the range;
Greenspeed: The speed at which particle green changes in the life cycle;
Lifetime: Life cycle
Lifetimerange: Life cycle scope
Magnificationfilter: It's not clear that it seems to increase your size
Minificatonfilter: Reduce your size
Minificationfilterbias: Factor to reduce size
Name: Names of particles
Redrange: The color of a particle red can change the range;
RedSpeed; The rate at which the particle red changes in the life cycle;
Scale: Zoom ratio:
Scalerange: Scaling scale range;
Scalespeed: Zoom Rate:
Spin: Sub Rotation angle
Spinrange: Sub Rotation angle Range
Style: Not very clear:
Velocity: Speed
Velocityrange: Speed Range
Xacceleration: The acceleration component in the particle x direction
Yacceleration: The acceleration component in the Y direction of the particle
Zacceleration: The acceleration component in the z direction of a particle
2, Caemitterlayer
Caemitterlayer provides a particle emission system based on the core animation, and the particles are initialized with Caemittercell. The particle is painted on the border of the background layer box
Property:
birthrate: particle generation coefficient, default 1.0;
Emittercells: An array of Caemittercell objects used to put the particles on the layer;
Emitterdepth: Determining the depth of particle shape: emittershape
Emittermode: Launch mode
NSString * Const kcaemitterlayerpoints;
NSString * Const Kcaemitterlayeroutline;
NSString * Const Kcaemitterlayersurface;
NSString * Const Kcaemitterlayervolume;
Emitterposition: Launch Location
Emittershape: The shape of the transmitting source:
NSString * Const Kcaemitterlayerpoint;
NSString * Const Kcaemitterlayerline;
NSString * Const Kcaemitterlayerrectangle;
NSString * Const kcaemitterlayercuboid;
NSString * Const kcaemitterlayercircle;
NSString * Const Kcaemitterlayersphere;
Emittersize: The size of the launch source is large;
Emitterzposition: the z coordinate position of the emitter source;
Lifetime: Particle life cycle
Preservesdepth: Not much clearer (particles are flattened on layers)
Rendermode: Render mode:
NSString * Const kcaemitterlayerunordered;
NSString * Const Kcaemitterlayeroldestfirst;
NSString * Const Kcaemitterlayeroldestlast;
NSString * Const Kcaemitterlayerbacktofront;
NSString * Const kcaemitterlayeradditive;
Scale: the scaling ratio of particles:
Seed: Used to initialize seeds produced by random numbers
Spin: self-rotating speed
Velocity: particle velocity
Four, demo download
The above is the iOS particle system data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!