我是cocos2d的初学者,但我在Objective-C和iphoneSdk方面有一些经验。 但我的应用程序中有一个问题,我无法弄清楚错误是什么..
我有一个CCLayer(动漫),它向玩家显示一个小动画,然后它启动另一个CCLayer(等级):
动画:
-(id) init{
if( (self=[super init])) {
CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"Anime.plist"];
CCSprite * backgound = [CCSprite spriteWithSpriteFrameName:@"Back.png"];
backgound.anchorPoint=ccp(0,0);
[self addChild:backgound z:-1];
CCSprite *body = [CCSprite spriteWithSpriteFrameName:@"Body1.png"];
[self addChild:body z:0];
CCSprite *bMoved = [CCSprite spriteWithSpriteFrameName:@"Gigante1.png"];
[self addChild:bMoved z:1];
NSMutableArray *nuvemAnim = [[NSMutableArray alloc] init];
for (int i = 1; i < 41; i++) {
NSString *frameNames = [NSString stringWithFormat:@"Gigante%i.png",i];
[nuvemAnim addObject:[[CCSpriteFrameCache sharedSpriteFrameCache]
spriteFrameByName:frameNames]];
}
CCAnimation *gigAnim = [CCAnimation animationWithFrames:nuvemAnim delay:1.0f/24.0f];
CCAnimate* animate = [CCAnimate actionWithAnimation:gigAnim];
[bMoved runAction:[CCSequence actions:
[CCDelayTime actionWithDuration:1],
animate,
[CCDelayTime actionWithDuration:1],
[CCCallFunc actionWithTarget:self selector:@selector(changeCCScene)],
nil]];
}
return self;
在Level I中,使用CCSpriteFrameCache创建角色动画
等级:
-(id) init{
if( (self=[super init])) {
self.isTouchEnabled=YES;
CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"Level3.plist"];
CCSprite * backgound = [CCSprite spriteWithSpriteFrameName:@"Fundo9.png"];
backgound.anchorPoint=ccp(0,0);
[self addChild:backgound z:-1];
CCSprite man = [CCSprite spriteWithSpriteFrameName:@"Man1.png"];
[self man z:0];
eAnim = [[NSMutableArray alloc] init];
for (int i = 2; i < 178; i++) {
NSString *frameNames = [NSString stringWithFormat:@Man%i.png",i];
[eAnim addObject:[[CCSpriteFrameCache sharedSpriteFrameCache]
spriteFrameByName:frameNames]];
}
但是在控制台中无限制地为所有帧提供了这种类型的错误
2012-04-03 23:37:51.987 GigV1[1432:10a03] cocos2d: WARNING: an alias with name Man12.png already exists
2012-04-03 23:37:51.988 GigV1[1432:10a03] cocos2d: WARNING: an alias with name Man155.png already exists
为什么会发生这种情况?
由于
答案 0 :(得分:1)
此行中缺少引号:
NSString *frameNames = [NSString stringWithFormat:@Man%i.png",i];
应该是@
之后和Man%i
答案 1 :(得分:1)
您正在从Anime.plist和Level3.plist中加载精灵帧:
CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"Anime.plist"];
[frameCache addSpriteFramesWithFile:@"Level3.plist"];
此警告表示您正在添加更多具有相同名称的精灵帧:
WARNING: an alias with name Man12.png already exists
要解决此问题,您有三种选择: