Game Development Reference
In-Depth Information
spriteFrameByName:file] to create the sprite frame with the corresponding
name.
Updating the CCAnimation Helper Category
Although you could significantly reduce the code to create a CCAnimation by using
a texture atlas, it's still worthwhile to encapsulate this code into the CCAnima-
tionHelper class. After all, one line of code is still less than five lines, especially if
you would otherwise use the same five lines of code everywhere. Without further ado,
Listing 6-14 shows the extended CCAnimation Helper interface declaration, which
adds the animationWithFrame method.
Listing 6-14. The @interface for the CCAnimation Helper Category
interface CCAnimation (Helper)
+(CCAnimation*) animationWithFile:(NSString*)name
frameCount:(int)frameCount
delay:(float)delay;
+(CCAnimation*) animationWithFrame:(NSString*)frame
frameCount:(int)frameCount
delay:(float)delay;
@end
This code is essentially the same method using the same parameters, except that this
method uses sprite frames instead of filenames. The implementation is nothing spectac-
ular and is very similar to the animationWithFile method shown in Listing 6-15 .
Listing 6-15. The animationWithFrame Helper Method Makes It Easier to Create an
Animation
// Creates an animation from sprite frames
+(CCAnimation*) animationWithFrame:(NSString*)frame
frameCount:(int)frameCount
delay:(float)delay
{
// load the ship's animation frames as textures and create a sprite frame
 
 
 
 
Search Nedrilad ::




Custom Search