0
В моей игре, когда игрок сталкивается с флагом (используя DidBeginContact), я добавляю SKSpritenode «nextlevel» (который не отвечает в TouchesBegan, и я не знаю почему. Код NSLog в TouchesBegan не работаетSKSpritenode не отвечает в TouchesBegan
Это мой код:.
-(void)nextlevel
{
nextlevel = [SKSpriteNode spriteNodeWithImageNamed:@"nextlevel.png"];
nextlevel.userInteractionEnabled = NO;
nextlevel.name = @"nextlevel";
nextlevel.position = CGPointMake(self.size.width/2.0, self.size.height/2.0);
[self addChild:nextlevel];
}
- (void)didBeginContact:(SKPhysicsContact *)contact
{
SKPhysicsBody *firstBody, *secondBody;
if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask)
{
firstBody = contact.bodyA;
secondBody = contact.bodyB;
}
else
{
firstBody = contact.bodyB;
secondBody = contact.bodyA;
}
if((firstBody.categoryBitMask == playerCategory && secondBody.categoryBitMask == flagCategory) ||
(firstBody.categoryBitMask == flagCategory && secondBody.categoryBitMask == playerCategory))
{
// PLAYER WINS
NSLog(@"player touches flag");
SKAction * wait = [SKAction waitForDuration:1.2];
SKAction *performSelector = [SKAction performSelector:@selector(nextlevel) onTarget:self];
[self runAction:[SKAction sequence:@[wait, performSelector]]];
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
// Nextlevel splash screen
if ([node.name isEqualToString:@"nextlevel"]) {
NSLog(@“Next Level was touched!");
}
}
Установить nextlevel.userInteractionEnabled = YES; – Roecrew