因此,这里是我的场景问题:我从菜单场景开始,然后进入InGame场景,当角色死亡时,我再次进入菜单场景,所有这些使用:重新启动场景时发生崩溃
[[CCDirector sharedDirector] replaceScene:[MainMenu scene]];
和
[[CCDirector sharedDirector] replaceScene:[InGame scene]];
与错误输掉了比赛,并试图回到比赛,我SpriteSheet崩溃后:
'CCSprite is not using the same texture id'
这里是我的init动画:
- (void) initSprite:(NSString *)plist andTexture:(NSString *)texture_ {
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:plist];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:texture_];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for (int i=1; i<=12; i++) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%d.png",i]]];
}
CCAnimation *walkAnim = [CCAnimation animationWithSpriteFrames:walkAnimFrames delay:0.05f];
texture = [CCSprite spriteWithSpriteFrameName:@"1.png"];
walkAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:walkAnim]];
[texture runAction:walkAction];
texture.position = position;
texture.tag = HeroType;
[spriteSheet addChild:texture];
[self addChild:spriteSheet];
}
当我纹理添加到spriteSheet发生崩溃:
[spriteSheet addChild:texture];
我认为,问题来自于质感的释放..
我不使用ARC。
您在这里使用精灵表是多余的。对于使用initSprite创建的每个精灵,都会为该精灵创建一个精灵批处理节点。无论是否有批处理节点,您最终都会为每个精灵绘制一个绘图调用。批次不会加快动画速度,它们可以加速使用相同纹理渲染多个精灵,从而可以在一次绘制调用中显示10个或数百个相同的精灵。 – LearnCocos2D
我明白了,我正在用它来绘制一个正在运行的角色的动画。我有一个精灵12张精灵图(http://oi42.tinypic.com/2s6oe3n.jpg),你认为最好的方法是什么? – thegameg