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

カテゴリが機能するには、次の方法で新しいメソッドを定義する必要があります。これを参照してください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 に答える
0

あなたのヘルパーメソッドはどこにありますか? 独自のクラス内にある場合は、次のように呼び出す必要があります

[MyClass method];

いいえ

[CCAnimation method];

+メソッドが静的であることを意味するため、このメソッドが含まれるクラスで呼び出す必要があります。

于 2012-12-09T01:49:01.910 に答える