IOS Animation--The Fireworks effect example detailed _ios

Source: Internet
Author: User

Caemitterlayer provides a Core Animation particle launch System that enables a variety of particle animation effects. The effect of the fireworks here is based on Caemitterlayer.

Fire.gif

-(void) viewdidload {[Super viewdidload];
[Self makefireworksdisplay];
 }-(void) Makefireworksdisplay {//Particle Launch System initialization caemitterlayer *fireworksemitter = [Caemitterlayer layer];
 CGRect viewbounds = self.view.layer.bounds;
 The location of the emitter is fireworksemitter.emitterposition = Cgpointmake (viewbounds.size.width/2.0, viewBounds.size.height);
 Emission source Size fireworksemitter.emittersize = Cgsizemake (viewbounds.size.width/2.0, 0.0);
 Launch mode fireworksemitter.emittermode = Kcaemitterlayeroutline;
 The shape of the emitter source is Fireworksemitter.emittershape = Kcaemitterlayerline;
 The rendering mode Fireworksemitter.rendermode = Kcaemitterlayeradditive of the emitter source;

 The seed Fireworksemitter.seed = (Arc4random ()%100) +1, which is generated by the initialization random number of the transmitting source;
 /** * Add the launch point a circle (launch point) from the bottom of a process to launch to the above/caemittercell* rocket = [Caemittercell Emittercell]; Rocket.birthrate = 1.0; is the number of Effectcell produced at some point per second rocket.emissionrange = 0.25 * M_PI; Ambient firing angle rocket.velocity = 400; Speed Rocket.velocityrange = 100; Speed range rocket.yacceleration = 75;
 The acceleration component in the Y direction of the particleRocket.lifetime = 1.02;

 The life cycle of the Effectcell, how long it takes to display on the screen.
 The following is the content of the rocket, color, size setting rocket.contents = (ID) [[uiimage imagenamed:@ "Circle"] cgimage];
 Rocket.scale = 0.2;
 Rocket.color = [[Uicolor redcolor] cgcolor];
 Rocket.greenrange = 1.0;
 Rocket.redrange = 1.0;
 Rocket.bluerange = 1.0; Rocket.spinrange = M_PI;
 Sub rotation angle Range/** * Add the effect of explosion, suddenly the feeling of a big bit/caemittercell* burst = [Caemittercell Emittercell];
 Burst.birthrate = 1.0;
 burst.velocity = 0;
 Burst.scale = 2.5;
 Burst.redspeed =-1.5;
 Burst.bluespeed =+1.5;
 Burst.greenspeed =+1.0;

 Burst.lifetime = 0.35;
 /** * Add star diffusion particle/caemittercell* spark = [Caemittercell Emittercell];
 Spark.birthrate = 400;
 Spark.velocity = 125;
 Spark.emissionrange = 2* M_pi; Spark.yacceleration = 75;

 The acceleration component of the Y-direction of the particle spark.lifetime = 3;
 Spark.contents = (ID) [[uiimage imagenamed:@ ' star '] cgimage];
 Spark.scalespeed =-0.2;
 Spark.greenspeed =-0.1;
 Spark.redspeed = 0.4;
 Spark.bluespeed =-0.1; Spark.alphaspeed =-0.25; Examples of changes in transparencySpeed Spark.spin = 2* m_pi;

 Sub rotation angle Spark.spinrange = 2* m_pi;
 Combine caemitterlayer and Caemittercell fireworksemitter.emittercells = [Nsarray arraywithobject:rocket];
 Adding explosive particles on the basis of circle particles rocket.emittercells = [Nsarray Arraywithobject:burst];
 Adding star particles burst.emittercells = [Nsarray Arraywithobject:spark] on the basis of exploding particles;

Add to layer [Self.view.layer addsublayer:fireworksemitter];

 }

Caemitterlayer

Caemitterlayer is a particle engine provided by quartzcore that can be used to make beautiful particle effects. In fact, it can be said that it is loaded Caemittercell container, there is a property emittercells, the Caemittercell directly added to the array, you can achieve the particle effect.

Might use a property
* birthrate: Particle generation coefficient, default 1.0;
* Emittercells: An array of Caemittercell objects that are used to put the particles on the layer;
* Emitterdepth: Determining the depth of particle shape contact: emittershape
* Emittermode: Launch mode
* Emitterposition: Launch location
* Emittershape: The shape of the transmitting source;
* 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:
* Scale: the scaling ratio of particles:
* Seed: Used to initialize the seed produced by random numbers
* Spin: self-rotating speed
* Velocity: particle velocity

Caemittercell

Caemittercell is used to represent a particle, and it has a series of parameters for setting the effect.

Properties that may be used
* birthrate This must be set, the specific meaning is the number of Effectcell per second.
* Alpharange: The range by which the color alpha of a particle can change;
* Alphaspeed: The speed at which particle transparency changes during the life cycle;
* 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 the particle
* Contents: is a Cgimageref object, both particles to show the picture;
* Contentsrect: The son rectangle should be painted in contents:
* Emissionlatitude: Angle of the direction of the z-axis of the launch
* Emissionlongitude:x-y plane of the launch direction
* Emissionrange; angle of firing around
* Emittercells: particle emitted by particles
* Enabled: Whether the particle is rendered
* Greenrange: The color of a particle green can change the range;
* Greenspeed: Change the speed of particle green in the life cycle;
* Lifetime: Life cycle
* Lifetimerange: Life cycle scope
* Magnificationfilter: Not very clear as if to increase their size
* Minificatonfilter: Reduce your size
* Minificationfilterbias: Factor to reduce size
* Name: The name of the particle
* 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 the particle

The feeling caemitterlayer is a very interesting dongdong, at present first the basic knowledge point notes here, still needs the unceasing actual combat experience to be able to use it better.
Note reference: http://www.jb51.net/article/93043.htm

Text/Sky Ball (Jane book author)
Original link: http://www.jianshu.com/p/08cbe521afe5
Copyright belongs to the author, reprint please contact the author to obtain authorization, and labeled "Jane Book author".

Related Article

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.