1

I am trying to get an Animation Helper with a cocos2d project and for some reason keep getting an error message:

unrecognized selector sent to class.

I have tried numerous approaches to no avail. I understand that it may have to do with a class-instance conflict, but I do not know how to resolve it. Any thoughts?

This is how I am calling the helper function:

CCAnimation* anim = [CCAnimation animationWithFrame:playerAnimName frameCount:1 delay:0.08f];

And this is the helper function itself:

     +(CCAnimation*) animationWithFrame:(NSString*)frame frameCount:(int)frameCount       delay:(float)delay
{
printf("start helper");

// load the players's animation frames as textures and create a sprite frame
NSMutableArray* frames = [NSMutableArray arrayWithCapacity:frameCount];
for (int i = 1; i < frameCount+1; i++)
{
    NSString* file = [NSString stringWithFormat:@"%@%i.png", frame, i];
    CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];

    [frameCache addSpriteFramesWithFile:@"maze-art.plist"];


    CCSpriteFrame* frame = [frameCache spriteFrameByName:file];
    [frames addObject:frame];
}

// return an animation object from all the sprite animation frames
return [CCAnimation animationWithSpriteFrames:frames delay:delay];
}

Any insight is appreciated. Thanks!

4

2 回答 2

0

你的辅助方法在哪里?如果它在您自己的班级内,则必须将其称为

[MyClass method];

不是

[CCAnimation method];

+意味着该方法是静态的,因此您必须使用该方法所在的类来调用它。

于 2012-12-09T01:49:01.910 回答
0

为了使类别起作用,您必须按以下方式定义新方法。请参考这个http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/chapters/occategories.html

@interface ClassName ( CategoryName )
// method declarations
@end

例如,您的新方法必须定义为

@interface CCAnimation (Helper)
+(CCAnimation*) animationWithFile:(NSString*)name frameCount:(int)frameCount delay:(float)delay
{
       ...
}
@end
于 2012-12-07T22:17:15.840 回答