IOS-Cocos2d Game Development 10: adding particle system effects and solving the coordinate problem between particle effects and layer;

Source: Internet
Author: User

Li huaming himiOriginal, reprinted must be explicitly noted:
Reprinted from[Heimi gamedev block]Link: http://www.himigame.com/iphone-cocos2d/472.html

Himi has always wanted to use the Particle System in the game, but it was found that the effect of using particles in the j2's and Android systems would put a burden on the running memory of the game, so it has been a pity that, in iOS game development, it can be said that particles must be used, or Apple hardware is powerful. I once read the cocos2d blog post, I said that the cocos2d particle editor is awesome, that's why I chose the cocos2d engine;

Particle editor name: particle designer. The interface is as follows:

Two days ago, the particle editor was successfully purchased (very cheap, less than 10 dollars, much cheaper than the image packaging tool TP). After two days, I regretted it, although this particle editor looks at the interface like the author of the Development Editor provides many special effects, it is actually an example of cocos2d, but in turn, the time that people save for visual editing is far worth the editor's money! Ke, and pulled far away, back to the question;

As for the method of adding particle effects to the editor or cocos2d, I will not talk about the n-plus materials and tutorials on the Internet. The following describes the key issues today;

To help you better understand the problem, I create a cocos2d project:

1. First draw a string on the screen (add a cclabelttf object to the current layer );

CCLabelTTF *label = [CCLabelTTF labelWithString:@"Welcome--Himi" fontName:@"Marker Felt" fontSize:64];CGSize size = [[CCDirector sharedDirector] winSize];label.position =  ccp( size.width /2 , size.height/2 );[self addChild: label];

2. then I will use a meteorite-like generated by the particle editor to export a file named "himi. plist "particle file (which contains all attributes of the particle), import the file to the project and add it to the current layer;

// Add a particle effect ccparticlesystem * tempsystem = [arch_optimal_participant le_system participant ithfile: @ "himi. plist "]; // tempsystem. positiontype = kccpositiontyperelative; // Note 1 tempsystem. positiontype = kccpositiontypefree; tempsystem. position = CCP (100,100); [self addchild: tempsystem];

Note 1 here. You should pay attention to it. We will go into details later. Ignore it first. Here, a string and a particle effect are added to the entire layer! The running project is as follows:

Here we will talk about it. I set the particle to keep playing cyclically. It is the parameter modified through the editor. OK. The following is the focus:

Now I use a selector [self scheduleupdate]; To keep the X coordinates of the current layer ++ 3. The Code is as follows:

-(void)update:(ccTime)time{    self.position=ccp(self.position.x+3,self.position.y);}

Here, I want to use the overall value assignment as much as possible for cocos2d coordinate modification. For example, if I want to change the coordinates, although I only change the X axis, I still modify the entire position;

Then everyone should know that the particle effects on the current layer and the cclabelttf will move along, but sorry, there is a problem here and the operation is as follows:

It must be strange that the particle effect should be vertical, but not actually. In fact, this problem is very detailed, because generally, particle effects are used for playing and disappearing in a short time;

Here we will talk about it. In fact, the transmitter of the special effect, that is, the starting coordinate of the particle, has actually been moving along with the layer, but the particle after being created has been shown as its own motion at the time of creation, we did not move the entire data as we imagined;

After talking about so many things, this problem can be solved by a single code, that is, Note 1 of the Code for creating particle effects at the top,

// Tempsystem. positiontype = kccpositiontyperelative; // Note 1

This positiontype is actually used to set the position types of all particles in the current particle effect. By default, it is in free mode. The Code is as follows:

kCCPositionTypeFree

In the remarks 1, kccpositiontyperelative is the relative mode, so you only need to set the position type of the particle to the relative mode here. The problem is solved;

OK, the kids shoes should have said, so it is easy to describe clearly the problem and the solution. = I think so too, but here I need to say two points:

1. if the blog post addresses the problem, balabara says a bunch of things, it is useless for children's shoes that haven't touched the particle. They are the monks of zhang'er, xxxx, you know ~

2. If I talk so much about it, I always say: Details determine success or failure. In fact, the details are just like the Foundation, and the foundation is poor. Why do you want to improve ?!

Well, this article is here, continue to be busy; now: lingcheng 1.24, ah, the latest blog posts are sent at night, no one will see the next day, =. =

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.