Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 6: Sprites In-Depth > Animation Helper Category

Animation Helper Category

Since the code to create the animation frames and the animation is common to all animations, you should consider encapsulating this into a helper method. I have done so in the project Sprite05_WithAnimHelper. Instead of using static methods, I decided to extend the CCAnimation class using an Objective-C feature called a category. It offers a way to add methods to an existing class without having to modify the original class. The only downside is that with a category you cannot add member variables to the class; you can only add methods. The following code is the @interface for the CCAnimation category, which I simply named Helper:

@interface CCAnimation (Helper)
+(CCAnimation*) animationWithFile:(NSString*)name
                       frameCount:(int)frameCount
                            delay:(float)delay;
@end

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint