Pregunta

I want to make particles inside the rectangle.

What is wrong in this code? It is emitted from only the emitter position, not, random position in rectangle.

fireEmitter = [CAEmitterLayer layer];
[self.view.layer fireEmitter];
fireEmitter.emitterPosition = self.view.center;
fireEmitter.emitterSize =CGSizeMake(100, 100);
fireEmitter.renderMode = kCAEmitterLayerRectangle;
fireEmitter.emitterCells = [NSArray arrayWithObjects:fire, nil];
¿Fue útil?

Solución

kCAEmitterLayerRectangle is not a valid value for renderMode. Instead you should use one of these values

kCAEmitterLayerUnordered
kCAEmitterLayerOldestFirst
kCAEmitterLayerOldestLast
kCAEmitterLayerBackToFront
kCAEmitterLayerAdditive

The kCAEmitterLayerRectangle value should be set as the emitterShape which defaults to kCAEmitterLayerPoint. That is why you are only emitting from a single point. The valid emitterShapes are:

kCAEmitterLayerPoint
kCAEmitterLayerLine
kCAEmitterLayerRectangle
kCAEmitterLayerCuboid
kCAEmitterLayerCircle
kCAEmitterLayerSphere

Please refer to the documentation for their meaning.

Otros consejos

As David already pointed out the value you are using isn't valid for renderMode. It is used in emitterShape. This can be a very frustrating error because Xcode doesn't give you a warning since they are of the same type (NSString). Such an error can easily be overlooked even having read the documentation.

Using a tool like Particle Playground (for UIKit emitters) or Particle Designer (for cocos2d emitters) can help a lot since they only allow the values as specified in the documentation.

They both let you configure your emitter layer/cell on your mac. Particle Playground exports the emitter as an objective c class for easy import in your project. Particle Designer exports in an exchange format which can easily be imported into the correct cocos2d emitter classes.

Full disclosure: I wrote Particle Playground and I do not have any affiliation with Particle Designer (even though I really like, use and recommend it for cocos2d projects).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top