0
我有兩個場景 - 在GameScene
我得到勝利計數並將其保存到BonusScene
,每件事情都很好,但我想每次顯示GameScene
贏得計數,我在BonusScene
重新啓動應用程序它顯示右算,但在GameScene
它1.從這裏開始就是我一直在使用:GameScene.m保存,加載和更新贏得計數使用NSUserDefaults在目標c
-(void)winCount{
win++;
winningCount =winningCount +win;
NSLog(@"%i",win);
NSUserDefaults *scoreprefs = [NSUserDefaults standardUserDefaults];
[scoreprefs setInteger:winningCount forKey:@"winningCount"];
winLabel = [SKLabelNode labelNodeWithFontNamed:@"ROTORcapExtendedBold"];
winLabel .fontSize = 70.f;
winLabel .position = CGPointMake(CGRectGetMidX(self.frame)+(CGRectGetMidX(self.frame)/2),CGRectGetMidY(self.frame));
winLabel .zPosition = 5;
winLabel .text = [NSString stringWithFormat:@"%ld",(long)winningCount];
[self addChild:winLabel];
而且在BonusScene.m
@implementation BonusScene
@synthesize winningCount;
-(id)initWithSize:(CGSize)size{
NSUserDefaults *scoreprefs = [NSUserDefaults standardUserDefaults];
self = [super initWithSize:size];
if (self){
winningCount =[scoreprefs integerForKey:@"winningCount"];
SKLabelNode *wins = [SKLabelNode labelNodeWithFontNamed:@"ROTORcap Extended Bold"];
wins.text =[NSString stringWithFormat:@"%ld",(long)winningCount ];
wins.position = CGPointMake(CGRectGetMidX(self.frame) + 100,(CGRectGetMidY(self.frame)) + self.frame.size.height/4);
wins.fontSize = 15.f;
[self addChild:wins]
如何在GameScene
中更新它,以便顯示與BonusScene
相同的結果?
是的,現在的工作,謝謝! – artG