IOS_31_cocos2d _ Particle System

Source: Internet
Author: User

IOS_31_cocos2d _ Particle System
Finally:

The particle system is a base class,Particle SystemThe only direct subclass of is: maid.Particle systemquad <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Vc3Ryb25nPjxzdHJvbmc + weight + CjxzdHJvbmc + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140928/20140928103721124.png" alt = "\">

The following describes [Particle Designer]






Generate two files, one small texture and one plist


The plist file structure is as follows:


Use the plist file generated above to customize particle Effects


In cocos2d v3, it is important:

CCParticleSystemBase replaces the previous version of CCParticleSystem

CCParticleSystem replaces the previous version of CCParticleSystemQuad

Therefore, in versions earlier than v3CCParticleSystemQuad

Therefore, in Versions later than v3, CCParticleSystem can be used to customize particles.



CCParticleBatchNode,

Like spriteBatchNode, multiple identical images are created using the same texture.Special effects(For example, in different positions on the screen ),

You can add it to the same batchNode for unified management;

In this scenario, you only need to deal with one batchNode, and only one Node is displayed on the interface.

//// Maid. m // 31_cocos2D getting started /// Created by beyond on 14-9-27. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "maid. h "@ interface participant scene () {// demonstrate the built-in particle effect CCParticleSystem * _ participant system; // display the particle effect name CCLabelTTF * _ label ;} @ end @ implementation maid # pragma mark-Override parent class method-(id) init {if (self = [super init]) {// 1. Scene Node allows interaction with self. userInteractionEnabled = YES; // 2. display the particle effect name _ label = [CCLabelTTF labelWithString: @ "" fontName: @ "Marker Felt" fontSize: 30]; _ label. positionType = CCPositionTypeNormalized; // in the upper-right corner of the screen, note that the Cartesian coordinate system is used, and the origin is in the lower-left _ label. position = ccp (0.7f, 0.75f); _ label. horizontalAlignment = CCTextAlignmentRight; [self addChild: _ label];} return self ;}// directly overwrite, that is, you do not need to create a sprite In Center-(void) addSpriteInCenter {} // method for implementing the parent class, add a button to the screen-(void) addShowBtns {// 1. use the default particle effect [self addBtn: @ "[System Particle]" position: ccp (0, 0) target: self sel: @ selector (systemparticipant clicked)]; // 2. use the particle designer [self addBtn: @ "[particle Designer]" position: ccp (0, 0.1) target: self sel: @ selector (diyparticle clicked)]; // 3. use the particle batchnode [self addBtn: @ "[particle Batch]" position: ccp (0, 0.2) target: self sel: @ selector (participant batchnodeclicked)];} // display the default particle effect static int I = 0;-(void) systemparticipant clicked {// to add, first remove [_ participant system removeFromParent]; I ++; if (I> 11) {I = 1;} Class cls; switch (I) {case 1: cls = NSClassFromString (@ "CCParticleFire"); break; case 2: cls = NSClassFromString (@ "CCParticleFireworks"); break; case 3: cls = NSClassFromString (@ "CCParticleSun"); break; case 4: cls = NSClassFromString (@ "CCParticleGalaxy "); break; case 5: cls = NSClassFromString (@ "CCParticleFlower"); break; case 6: cls = NSClassFromString (@ "CCParticleMeteor"); break; case 7: cls = NSClassFromString (@ "canonical"); break; case 8: cls = NSClassFromString (@ "CCParticleExplosion"); break; case 9: cls = NSClassFromString (@ "CCParticleSmoke "); break; case 10: cls = NSClassFromString (@ "CCParticleSnow"); break; case 11: cls = NSClassFromString (@ "CCParticleRain"); break; default: break ;} _ particle system = [cls node]; // sets the custom texture and position, and returns to the scene (fire.png) _ particle system. texture = [CCTexture textureWithFile: @ "circle.png"]; _ participant system. position = ccp (self. contentSize. width/2, self. contentSize. height * 0.3); [self addChild: _ participant system]; // 2. display the particle effect name_label. string = NSStringFromClass (cls);} // custom particle effects, using the particle designer-(void) diyparticle clicked {CCParticleSystem * diyparticle system = [CCParticleSystem particle lewithfile: @ "circle. plist "]; diyparticipant system. position = ccp (self. contentSize. width/2, self. contentSize. height * 0.5); // added to the scenario [self addChild: diyparticle System];} // same as spriteBatchNode, multiple particle effects created using the same texture are used, you can add it to the same batchNode for unified management. In a scenario, you only need to deal with one batchNode, and only one-(void) Node is displayed on the interface) particle batchnodeclicked {// CCParticleBatchNode * batch = [CCParticleBatchNode batchNodeWithFile: @ ""]; // [batch addChild: p1, p2, p3];} @ end



Below are the built-in particle effects of the system, all of which are inherited fromParticle systemquad,

WhileParticle systemquadInherited from:Particle System

Note: The built-inThe effect of a particle must be a fire.png image.

However, you can use the texture property to set it separately.











Image Encoding: in a special plistfile, a key is used to include all images of an image. When creating a particle effect, no more. PNG images will be uploaded.

The following plist file,

The last key: textureImageData. All strings in it represent a complete image.

From the beginning, there is no need to import another .png Image


Similar image encoding also appears on the frame rate display number in the lower left corner of the cocos2d Screen

The director class determines the frame rate number displayed in the timeline


Command + Click to enter


After entering again, we found that the displayed frame rate is actually CCFPSLabel.


You can set a string for _ FPSLabel to display the frame rate in the lower left corner of the screen.


Then, how is _ FPSLabel instantiated? What is the texture used for the number displayed?

Please refer to the following picture. The focus is ~~~


Command + Click to enter the getFPSImageData Method

We found that the pointer datapointer points to another area in the memory:

Cc_fps_images_ipadhd_png


After entering, we found that these strings are the encoded data of the image.







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.