What is the best method to reuse animations for cocos2d?
I would like to be able to allocate a few actions so that I can use and reuse them again and again on whatever target CCNode I want. I assumed I could just load them up with a generic NSObject class in an init then call them when nessicary from a method but was unable to.
Was I just inept at my attempt or is there a more elegant solution?
@implementation Animation
@synthesize animation;
-(id) init
{
if ( (self=[super init]) ) {
animation = [CCScaleTo actionWithDuration: 0.15 scale: 2.0];
}
return self;
}
- (id) myAnimation
{
retur开发者_运维问答n animation;
}
[targetCCNode runAction:[Animation myAnimation]];
Creation an action is very fast. I don't think it's reasonable. If you want just to create actions with some common configuration then I suggest you to create (or use an existing one) a class with static methods for creating this actions. Or a singleton with non-static methods if you require some context when creating actions
精彩评论