Ihave two scenes GameScene
and BonusScene
I use NSUserDefaults
to save winning count, everything works fine, I add video reward ad, after watching video, you get 5 points, that works too, but score update on screen only happens when after you go to different scene and come back, but when I use NSLog()
I see that update happens, but I dont know how to do it in real time on screen. Here what I got:
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"]; }
So my question is How can I update Score in scene on screen in real time, without going to different scene and coming back?
Just update the text where you're updating the 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];
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments