我想安排一个 @selector(count) 间隔:1.0f 来计算剩余时间。这是我的代码:(在 GameManager.m 文件中)
-(void) count {
duration++;
[[[GameScene sharedScene] gadgetLayer] updateTimerLabel];
if (timeLimit - duration <= 5 && ticking == NO) {
ticking = YES;
[self schedule:@selector(untick) interval:5];
[[SimpleAudioEngine sharedEngine] playEffect:@"tick.caf"];
}
if (duration >= timeLimit) {
[self lose];
}
}
gadgetLayer 是我放置 timerLayer 和 scoreLayer 东西的地方。计数没有安排在 GameManager.m 中,而是我把它放在我的 GameScene.m 文件中:
-(void) onEnter {
[[GameManager sharedManager] schedule:@selector(count) interval:1.0];
[super onEnter
}
- (void)onExit {
[[GameManager sharedManager] unschedule:@selector(count)];
[super onExit];
}
但是 timerLabel 不会改变。计数方法在 GameManager.m 文件中,它必须在 GameScene.m 文件中吗?有什么问题吗?
+(GameManager*) sharedManager {
if (instanceOfGameManager == nil) {
return [[GameManager alloc] init];
}
else return instanceOfGameManager;
}
-(id) init {
if ((self = [super init])) {
instanceOfGameManager = self;
[self scheduleUpdate];
}
return self;
}`
-(void) update: (ccTime) delta {
int a = 2;
}
`
我在“int a = 2”行中设置了一个断点,但无法到达。[GameManager sharedManager] 在 appDidFinishLaunching 方法中被调用,所以我猜它不会被再次分配和初始化。