这是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”。为什么?我已经搜索过,但找不到任何解决方案。