gpt4 book ai didi

ios - CCAnimation 因无法识别的选择器 setDisplayFrame 而崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:09:49 25 4
gpt4 key购买 nike

我不知道为什么,但我的动画不工作。我现在正在尝试通过 Sprite 表但通过一组 Sprite 添加一个动画单元。出了点问题下面是初始化方法的代码:

@implementation Enemy
-(id) initAt:(CGPoint)pos
{
if([super init])
{
self.position = pos;
CCSprite *start_sprite = [CCSprite spriteWithFile:@"unit1_00000.png"];
start_sprite.position = ccp(0,0);
[self addChild:start_sprite z:2];

const int FRAMES_COUNT = 10;
NSMutableArray* frames = [[NSMutableArray alloc]initWithCapacity:FRAMES_COUNT];
for (int i = 0; i < FRAMES_COUNT; i++)
{
NSString* file = [NSString stringWithFormat:@"unit1_0000%i.png", i];
CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:file];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
[frames addObject:frame];
}


_default_animation = [CCAnimation animationWithSpriteFrames:frames delay:0.1f];
_current_anim_action = [CCAnimate actionWithAnimation:_default_animation];
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:_current_anim_action];
[self runAction:repeat];
}
return self;
}

错误如下:-[Enemy setDisplayFrame:]: unrecognized selector sent to instance 0x8929bd0

最佳答案

setDisplayFrameCCSprite 类的一个方法,所以为了在 Enemy 类上运行一个 CCAnimation (内部调用 setDisplayFrame),Enemy 必须扩展 CCSprite,而不是 CCNode

关于ios - CCAnimation 因无法识别的选择器 setDisplayFrame 而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19758054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com