簡體   English   中英

更改init中的sprite plist文件-cocos2d

[英]Change sprite plist file in the init - cocos2d

我正在用cocos2d進行游戲,並且我有一個騎士角色想要更改其精靈。 因此,在我的knight.m中,我這樣做了:

- (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"];
    }
}

所以基本上,我想騎士的精靈改變從knightL1.plistknightL2.plist基礎上,騎士的肥土...所以我在做什么在我的代碼,我分配騎士是串l1和分配l1l1_plistinitknightL3 然后在更新方法中,將l1l1_plist更改為另一個字符串。 問題是,如果肥胖度超過80 ,並且我將l1l1_plist字符串更改為其他字符串,則子畫面不會從knightL4.plist更改為knightL5.plist 那么如何使騎士隨着比賽的進行而根據脂肪變化呢?

提前致謝!

您發布的代碼應該可以工作。 嘗試在Fatness> 80的調試器中逐步執行它,然后查看執行了哪些行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM