0

これはMyScene.h次のとおりです。

#import <SpriteKit/SpriteKit.h>
@interface MyScene : SKScene
@property (nonatomic) int monstersDestroyed;
@end

これはMyScene.m次のとおりです。

if( someCondition ){
    self.monsterPassed++;
    NSLog(@"MonsterPassed : %d",self.monsterPassed);
}

コンソールには、「MonsterPassed : 0」...「MonsterPassed : 1」などと表示されます。うまく。

これはViewController.h次のとおりです。

#import <UIKit/UIKit.h>
#import <SpriteKit/SpriteKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *DestroyeCountLabel;
@end 

これはViewController.m次のとおりです。

#import "ViewController.h"
#import "MyScene.h"
@interface ViewController ()
@property (nonatomic) AVAudioPlayer * backgroundMusicPlayer;
@end

@implementation ViewController

- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];

MyScene *monsterDestroyerValue = [[MyScene alloc]init];

self.DestroyeCountLabel.text =[NSString stringWithFormat:@"Monster Destroyed:%d",monsterDestroyerValue.monstersDestroyed];
...
}

問題はViewController.m、ラベルに表示されず、「Monster Destroyed: 0」としか表示されないことです。なんで?すでに検索しましたが、解決策が見つかりません。

4

1 に答える 1

1

DestroyeCountLabel のテキストを一度だけ設定しています。この後に MonstersDestroyed 変数を設定しても、DestroyeCountLabel は自動的に更新されません。これを行う方法は無数にあります。私の提案は、飛び込む前にプログラミングをよりよく理解するために、Appleのチュートリアルのいくつかを通過することです.

于 2014-07-07T17:40:53.080 に答える