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 回答