Ios 更改init-cocos2d中的sprite plist文件

Ios 更改init-cocos2d中的sprite plist文件,ios,iphone,objective-c,cocos2d-iphone,Ios,Iphone,Objective C,Cocos2d Iphone,我正在cocos2d中制作一个游戏,我有一个骑士角色,我想把精灵换成它。所以在《我的骑士》中,我做到了: - (id)initWithKnightPicture { l1 = [NSString stringWithFormat:@"knightL3.png"]; l1_plist = [NSString stringWithFormat:@"knightL3.plist"]; self = [super initWithFile:l1];

我正在cocos2d中制作一个游戏,我有一个骑士角色,我想把精灵换成它。所以在《我的骑士》中,我做到了:

- (id)initWithKnightPicture {

        l1 = [NSString stringWithFormat:@"knightL3.png"];
        l1_plist = [NSString stringWithFormat:@"knightL3.plist"];

        self = [super initWithFile:l1];


    if (self) {

                [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:l1_plist];

        // ************* RUNNING ANIMATION ********************
        animationFramesRun = [NSMutableArray array];
        for(int i = 1; i <= 6; ++i) {
            [animationFramesRun addObject:
             [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"Level1-Run-hd-%d.png", i]]];
        }
    }
    return self;
}

- (void)update:(ccTime)delta
{
    if ([[GameMechanics sharedGameMechanics] game].fatness < 20) {
        l1 = [NSString stringWithFormat:@"knightL1.png"];
        l1_plist = [NSString stringWithFormat:@"knightL1.plist"];
    } else if ([[GameMechanics sharedGameMechanics] game].fatness < 40) {
        l1 = [NSString stringWithFormat:@"knightL2.png"];
        l1_plist = [NSString stringWithFormat:@"knightL2.plist"];
    } else if ([[GameMechanics sharedGameMechanics] game].fatness < 60) {
        l1 = [NSString stringWithFormat:@"knightL3.png"];
        l1_plist = [NSString stringWithFormat:@"knightL3.plist"];
    } else if ([[GameMechanics sharedGameMechanics] game].fatness < 80) {
        l1 = [NSString stringWithFormat:@"knightL4.png"];
        l1_plist = [NSString stringWithFormat:@"knightL4.plist"];
    } else if ([[GameMechanics sharedGameMechanics] game].fatness < 100) {
        l1 = [NSString stringWithFormat:@"knightL5.png"];
        l1_plist = [NSString stringWithFormat:@"knightL5.plist"];
    }
}
-(id)initWithKnightPicture{
l1=[NSString stringWithFormat:@“knightL3.png”];
l1_plist=[NSString stringWithFormat:@“knightL3.plist”];
self=[super initWithFile:l1];
如果(自我){
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:l1_plist];
//**********运行动画********************
animationFramesRun=[NSMutableArray];

对于(int i=1;i您发布的代码应该可以工作。请尝试在fatness>80的调试器中单步执行它,看看执行了哪些行。

很抱歉含糊不清…我更新了我的问题您的更新方法的内容是什么?这是您应该处理动画的地方,等等,init方法有一个用途,那就是initial i唱歌对象。你能再澄清一点问题吗?我更新了我的问题,做了更多的编辑和新的代码。嗯,你的意思是它对20到60岁之间的肥胖有效,当它达到80岁或以上时就停止工作了吗?是的,这是因为我可以在你的更新方法中看到你只是将
l1
l1_plist
设置为字符串,而不是doi如果他们有什么问题,也许你应该在最后一行之后做点什么?