-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
if ([node.name isEqualToString:@"play"]){
NSLog(@"play was touched");
SKScene *mainGameScene = [[MainGame alloc] initWithSize:self.size];
if (!mainGameScene){
SKTransition *transition = [SKTransition fadeWithColor:[UIColor blackColor] duration:0.5];
[self.view presentScene:mainGameScene transition:transition];
}
}
} 나의 이해에서시험이 아닌 경우
검사 위의 코드는 mainGameScene
이 전무 인 경우는 경우는 다음 if 문을 통해 이동합니다.
이 코드가있는 메서드를 여러 번 호출하면 SKScene
의 새 개체를 만들지 않으므로이 방법이 유용할까요 아니면 단지 코드 낭비입니까?
'if (! mainGameScene)'직전에/init'mainGameScene'을 할당하면 if 블록은 결코 사실이 아니므로 처음부터 실행되지 않습니다. – staticVoidMan
alloc/init 전에 객체를 테스트하려면 어떻게해야합니까? – Mutch95