Game Development Reference
In-Depth Information
To compare the two sprite frames, the isEqual: method is used. While in this case a
direct pointer comparison _triggerFrame == spriteFrame would have worked
too, it is better style to use isEqual: because many Objective-C objects can't be com-
pared through their pointer values alone.
This potential pitfall is best explained by example: you can create two instances of
CCColor , both using the same init method and parameters ( initWithWhite:1.0
alpha:1.0 ), yet you'll have two different objects occupying two different memory ad-
dresses.
The pointer equality test using the equality operator == will evaluate to NO (false), but us-
ing isEqual: gives CCColor the chance to compare its properties. Assuming the
isEqual: method is properly implemented, it will determine that all of its properties are
identical—in which case, isEqual: returns YES (true) even though both may be two
separate objects.
Particle Effects
Particle effects are possibly the best known type of visual effect, at least in 2D games. In
SpriteBuilder and Cocos2D, they're referred to as a particle system , which is the equival-
ent of the better known and more descriptive term particle emitter .
The CCParticleSystem node is a node that emits particles. Henceforth, I shall use emitter
when I refer to a particle system. It better describes what the node does.
Limitations of Particle Effects
The thing with particles is that they can be rendered more efficiently than if you were to
use the same number of sprites with the same behavior. The downside to that is that you
have absolutely no access or control over individual particles except for the parameters
provided by the emitter.
For instance, you can't access, remove, or otherwise modify specific particles. You can't
even identify or obtain references to individual particles, nor can you run actions on them.
While the particle system node itself can have physics enabled, there's little use in that:
individual particles will not collide with other physics bodies or other particles. Only the
emitter node as a whole can have a collision shape and can be moved about by the physics
engine. Unless the particle effect is designed to (roughly) contain all emitted particles
Search WWH ::




Custom Search