[英]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.plist
到knightL2.plist
基礎上,騎士的肥土...所以我在做什么在我的代碼,我分配騎士是串l1
和分配l1
和l1_plist
在init
是knightL3
。 然后在更新方法中,將l1
和l1_plist
更改為另一個字符串。 問題是,如果肥胖度超過80
,並且我將l1
和l1_plist
字符串更改為其他字符串,則子畫面不會從knightL4.plist
更改為knightL5.plist
。 那么如何使騎士隨着比賽的進行而根據脂肪變化呢?
提前致謝!
您發布的代碼應該可以工作。 嘗試在Fatness> 80的調試器中逐步執行它,然后查看執行了哪些行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.