我有两个场景GameScene
和BonusScene
我使用NSUserDefaults
来保存获胜计数,一切正常,我添加视频奖励广告,看完视频后,你得到5分,有效也是,但屏幕上的分数更新只发生在你去不同的场景后回来,但是当我使用NSLog()
时,我看到更新发生了,但我不知道如何在屏幕上实时进行。
这就是我得到的:
losingCount=[scoreprefs integerForKey:@"losingCount"];
SKLabelNode *winsCoutnt = [SKLabelNode labelNodeWithFontNamed:@"ROTORcap Extended Bold"];
winsCoutnt.text =[NSString stringWithFormat:@"%ld",(long)losingCount];
winsCoutnt.position = CGPointMake(CGRectGetMidX(self.frame) + 100,(CGRectGetMidY(self.frame)) + self.frame.size.height/4 );
winsCoutnt.fontSize = 15.f;
[self addChild:winsCoutnt];
if([Chartboost hasRewardedVideo:@"NetworkVideo"] == YES) {
NSUserDefaults *scoreprefs = [NSUserDefaults standardUserDefaults];
losingCount =[scoreprefs integerForKey:@"losingCount"];
losingCount = losingCount +5;
[scoreprefs setInteger:losingCount forKey:@"losingCount"]; }
所以我的问题是如何在屏幕上实时更新分数,而不会进入不同的场景并回来?
答案 0 :(得分:1)
只需更新您正在更新NSUserDefaults的文本
losingCount=[scoreprefs integerForKey:@"losingCount"];
SKLabelNode *winsCoutnt = [SKLabelNode labelNodeWithFontNamed:@"ROTORcap Extended Bold"];
winsCoutnt.text =[NSString stringWithFormat:@"%ld",(long)losingCount];
winsCoutnt.position = CGPointMake(CGRectGetMidX(self.frame) + 100,(CGRectGetMidY(self.frame)) + self.frame.size.height/4 );
winsCoutnt.fontSize = 15.f;
[self addChild:winsCoutnt];
if([Chartboost hasRewardedVideo:@"NetworkVideo"] == YES) {
NSUserDefaults *scoreprefs = [NSUserDefaults standardUserDefaults];
losingCount =[scoreprefs integerForKey:@"losingCount"];
losingCount = losingCount +5;
[scoreprefs setInteger:losingCount forKey:@"losingCount"];
winsCoutnt.text =[NSString stringWithFormat:@"%ld",(long)losingCount];
}