来自助手的呈现场景 class
Present Scene from a helper class
我正在为 iOS 开发一款具有游戏货币的游戏。我有一个 SKSceneStore,它有一个显示玩家游戏内财富的 SKLabelNode。当用户导航到 SKSceneStore 时(从保存的 NSUserDefaults 值)初始化此标签的值。
为了让用户购买更多的游戏内货币,我有一个助手 class,IAPHelper(来自 Ray Wenderlich 的教程:http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial and http://www.raywenderlich.com/23266/in-app-purchases-in-ios-6-tutorial-consumables-and-receipt-validation),其中一种方法是 "provideContentForProductIdentifier:(NSString *)productIdentifier".这是交易成功后调用的方法,我给玩家的游戏内财富增加了XXX游戏币。
我的问题是我不确定如何 'refresh' SKLabelNode 与用户的游戏内财富(在 SKSceneStore 中)。我怎样才能做到这一点?我想到的一个粗略的解决方案是我可以使用以下代码重新加载整个 SKSceneStore:
SKSceneStore *reinitializeStore = [SKSceneStore alloc]init];
SKTransition *reveal = [SKTransition fadeWithDuration:0.5];
[reinitializeStore.view presentScene:reinitializeStore transition:reveal];
但是,此代码不起作用。
不能直接把标签从场景中移除,用更新后的财富创建一个新的标签,再添加回场景吗?
我设法找到了一个更优雅的解决方案并使用了以下代码:
在"provideContentForProductIdentifier:(NSString *)productIdentifier"
[[NSNotificationCenter defaultCenter] postNotificationName:@"reinitializeStore" object:self];
然后在我的 SKSceneStore 中我使用了
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(powerUpHUD) name:@"reinitializeStore" object:nil];
我正在为 iOS 开发一款具有游戏货币的游戏。我有一个 SKSceneStore,它有一个显示玩家游戏内财富的 SKLabelNode。当用户导航到 SKSceneStore 时(从保存的 NSUserDefaults 值)初始化此标签的值。
为了让用户购买更多的游戏内货币,我有一个助手 class,IAPHelper(来自 Ray Wenderlich 的教程:http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial and http://www.raywenderlich.com/23266/in-app-purchases-in-ios-6-tutorial-consumables-and-receipt-validation),其中一种方法是 "provideContentForProductIdentifier:(NSString *)productIdentifier".这是交易成功后调用的方法,我给玩家的游戏内财富增加了XXX游戏币。
我的问题是我不确定如何 'refresh' SKLabelNode 与用户的游戏内财富(在 SKSceneStore 中)。我怎样才能做到这一点?我想到的一个粗略的解决方案是我可以使用以下代码重新加载整个 SKSceneStore:
SKSceneStore *reinitializeStore = [SKSceneStore alloc]init];
SKTransition *reveal = [SKTransition fadeWithDuration:0.5];
[reinitializeStore.view presentScene:reinitializeStore transition:reveal];
但是,此代码不起作用。
不能直接把标签从场景中移除,用更新后的财富创建一个新的标签,再添加回场景吗?
我设法找到了一个更优雅的解决方案并使用了以下代码:
在"provideContentForProductIdentifier:(NSString *)productIdentifier"
[[NSNotificationCenter defaultCenter] postNotificationName:@"reinitializeStore" object:self];
然后在我的 SKSceneStore 中我使用了
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(powerUpHUD) name:@"reinitializeStore" object:nil];