1

我有一个项目,当我点击时,我会检查点击是否在特定节点上。如果是,那么我在该位置创建一个新的 SpriteNode,该位置仅在 0.1 秒内可见,然后才被删除。我希望能够在屏幕上进行垃圾邮件点击,但是通过当前检查,我最终点击的节点是我创建的新 SpriteNode。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {    
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];
        SKNode *node = [self nodeAtPoint:location];

        if (node == shutdahellup){
            [self runAction:[SKAction playSoundFileNamed:@"shut-da-hell-uh.mp3" waitForCompletion:NO]];
        }else if (node == hotdamn){
            [self runAction:[SKAction playSoundFileNamed:@"hot-damn.mp3" waitForCompletion:NO]];
        }else if (node == wafflewednesday){
            [self runAction:[SKAction playSoundFileNamed:@"waffle-wednesday.mp3" waitForCompletion:NO]];
        }else if (node == damnwaffle){
            [self runAction:[SKAction playSoundFileNamed:@"get-a-damn-waffle.mp3" waitForCompletion:NO]];
        }
        [self createFace:touch];
    }
}
-(void) createFace:(UITouch *)touch {
    SKSpriteNode * face = [SKSpriteNode spriteNodeWithImageNamed:@"shane.png"];
    CGPoint location = [touch locationInNode:self];
    face.position = location;
    face.zPosition = 100;

    [self addChild:face];

    SKAction * wait = [SKAction waitForDuration:0.1];
    SKAction * remove = [SKAction removeFromParent];

    SKAction * sequence = [SKAction sequence:@[wait, remove]];
    [face runAction:sequence];
}

有任何想法吗?谢谢!

4

0 回答 0