我正在尝试使用自定义动画删除CCMenuItem并崩溃...
- (void)removeCCMenuItem:(id)sender {
CCMenuItemSprite *menuItem = (CCMenuItemSprite *)sender;
CCSprite *animationSprite = [CCSprite spriteWithSpriteFrameName:@"AnimatedImage_01.png"];
[fixedSprite setScaleX: menuItem.contentSize.width/animationSprite.contentSize.width];
[fixedSprite setScaleY: menuItem.contentSize.height/animationSprite.contentSize.height];
animationSprite.position = ccp(menuItem.contentSize.width/2,menuItem.contentSize.height/2);
[menuItem addChild:animationSprite];
NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 1; i <= 5; ++i) {
[animFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"AnimatedImage_%02d.png", i]]];
}
CCAnimation *anim = [CCAnimation animationWithFrames:animFrames delay:0.05f];
CCActionInterval *animAction = [CCAnimate actionWithAnimation:anim restoreOriginalFrame:NO];
id seq = [CCSequence actions: animAction, [CCCallFunc actionWithTarget:animationSprite selector:@selector(removeFromParentAndCleanup:)], [CCCallFunc actionWithTarget:menuItem selector:@selector(removeFromParentAndCleanup:)], nil];
[menuItem runAction:seq];
}
知道它崩溃的原因吗?
日志说:
reason: '-[CCMenuItemSprite isFrameDisplayed:]: unrecognized selector sent to instance
答案 0 :(得分:2)
您正在CCMenuItem的子类上运行该操作,而在这种情况下,我认为您需要在精灵本身上运行它。
尝试更改:
[menuItem runAction:seq];
要:
[animationSprite runAction:seq];