开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜