【发布时间】:2014-04-23 13:16:46
【问题描述】:
我有一个如下所示的 CCNode 类:
#import "CCAnimation.h"
#import "Gameplay.h"
#import "ZAFSingletonCenter.h"
@interface Gameplay ()
{
}
@property (nonatomic, strong) CCSprite *character;
@property (nonatomic, strong) CCAction *talkAction;
@end
@implementation Gameplay{
NSMutableString *gesture;
NSString *characterName;
NSString *plist;
NSString *gestureSprite;
NSString *framefilename;
}
- (void)regresar {
CCScene *mainScene = [CCBReader loadAsScene:@"MainScene"];
[[CCDirector sharedDirector] replaceScene:mainScene];
}
- (void)didLoadFromCCB {
ZAFSingletonCenter *temporal = [ZAFSingletonCenter sharedManager];
characterName = temporal.personajeActual;
gesture = [@"fotos" mutableCopy];
plist = [NSString stringWithFormat:@"%@/%@.plist",characterName,gesture];
gestureSprite = [NSString stringWithFormat:@"%@/%@.png",characterName,gesture];
framefilename = [NSString stringWithFormat:@"%@/%@/%@_%@_",characterName,gesture,characterName,gesture];
[self loadGesture:characterName withGesture:gesture];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:plist];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:gestureSprite];
[self addChild:spriteSheet];
// *** This block should be moved outside the init or didLoadFromCCB
// *** and to the moveCharacter:withGesture method... once I make it work
NSMutableArray *actionFrames = [NSMutableArray array];
for (int i=1001; i<=1020; i++) {
[actionFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@%d.png",framefilename,i]]];
//NSLog(@"%@%d.png",_framefilename,i);
}
CCAnimation *gestureAction = [CCAnimation animationWithSpriteFrames:actionFrames delay:0.0666f];
CGSize viewSize = [[CCDirector sharedDirector] viewSize];
NSString *spriteCover = [NSString stringWithFormat:@"%@/%@/%@_%@_1011.png",characterName,gesture,characterName,gesture];
self.character = [CCSprite spriteWithImageNamed:spriteCover];
self.character.position = ccp(viewSize.width/2, viewSize.height/2);
[spriteSheet addChild:self.character z:99];
self.talkAction = [CCActionRepeatForever actionWithAction:
[CCActionAnimate actionWithAnimation:gestureAction]];
[self.character runAction:self.talkAction];
NSString *logMessage = self.character.debugDescription;
NSLog(@"---> %@",logMessage);
NSLog(@"---> %d",self.character.isRunningInActiveScene);
NSString *gestureMessage = gestureAction.debugDescription;
NSLog(@"---> %@",gestureMessage);
NSString *actionMessage = self.talkAction.debugDescription;
NSLog(@"---> %@",actionMessage);
// *** ending the block to be taken to the moveCharacter:withGesture method
}
- (void)actionA {
//testingButton A action
NSLog(@"A");
[self.character stopAction:self.talkAction];
}
- (void)actionB {
//testingButton B action
NSLog(@"B");
[self.character runAction:self.talkAction];
}
@end
这应该在屏幕中间有一个动画角色,并且它在一个空项目上。但是当我将它包含在实际项目中时,动画会在我定义为“spriteCover”的帧上保持暂停。完全没有错误,只是没有播放动画。
我尝试使用 -(id)init 而不是 -(void)didLoadFromCCB,但结果相同。我已经跟踪了几个步骤(您可以在上面的代码中查看日志部分),并且对我来说一切都很好。以下是打印的行:
---> <CCSprite = 0x15693a50 |
Rect = (281.50,568.50,147.00,268.00) |
tag = (null) | atlasIndex = 0>
---> 0
---> <CCAnimation = 0x15692de0 |
frames=20, totalDelayUnits=20.000000,
delayPerUnit=0.066600, loops=1>
---> <CCActionRepeatForever = 0x15694470 | Tag = -1>
我添加了两个触发 actionA 和 actionB 的按钮,当在 actionB 上点击两次时出现错误(如预期的那样),因为reason: 'runAction: Action already running'
【问题讨论】:
-
日志中打印了什么?也许找不到文件,也许您没有将它们添加到项目(或正确的目标)?您的格式字符串是否正确匹配文件名,包括大写/小写和数字格式?
-
感谢LearnCocos2D的回复。是的,您可以在上面的 NSLog 行中看到结果。我做了一些测试,故意更改路径和文件名,以查看控制台上打印的“要找到的文件”错误。我不得不说没有停止应用程序本身的错误。只是动画一直处于暂停状态。
标签: ios objective-c cocos2d-iphone xcode5