每次更新文本时,如何停止翻阅文本。每次文本更新时,它都会将文本放在上一个文本的顶部。这是我用来实现HUD的代码。
HUD设置
-(void)createHUD {
id wait = [SKAction waitForDuration:1.5];
id run = [SKAction runBlock:^ {
//delete after 1.5 seconds then reset it so that it doesnt overlap cuase its really annoying to watch that happen
counter++;
updateLabel = true;
counterLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
counterLabel.name = @"myCounterLabel";
//counterLabel.text = @"0";
counterLabel.fontSize = 50;
counterLabel.fontColor = [SKColor yellowColor];
counterLabel.position = CGPointMake(self.size.width / 2.0f, self.size.height / 1.3f);
[self addChild: counterLabel];
}];
[self runAction:[SKAction sequence:@[wait, run]]];
[self runAction:[SKAction repeatActionForever:[SKAction sequence:@[wait, run]]]];
}
更新方法
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
if(updateLabel == true) {
counterLabel.text = [NSString stringWithFormat:@"%i",counter];
updateLabel = false;
}
}
答案 0 :(得分:1)
您的代码存在一些问题:
看看以下方法。它应该能够实现你的目标。
-(void)createHUD {
counterLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
counterLabel.name = @"myCounterLabel";
//counterLabel.text = @"0";
counterLabel.fontSize = 50;
counterLabel.fontColor = [SKColor yellowColor];
counterLabel.position = CGPointMake(self.size.width / 2.0f, self.size.height / 1.3f);
[self addChild: counterLabel];
id wait = [SKAction waitForDuration:1.5];
id run = [SKAction runBlock:^ {
counter++;
counterLabel.text = [NSString stringWithFormat:@"%i",counter];
}];
[self runAction:[SKAction sequence:@[wait, run]]];
[self runAction:[SKAction repeatActionForever:[SKAction sequence:@[wait, run]]]];
}
注意:从更新方法中删除与计数器标签相关的任何代码。