iOS SpriteKit - 触摸特定位置,想要特定zPosition的节点

时间:2015-05-12 17:47:38

标签: ios touch zposition

我有一个项目,当我点击时,我检查点击是否在特定节点上。如果是,那么我在该位置创建一个新的SpriteNode,只有在被删除之前才能显示.1s。我希望能够在屏幕上点击垃圾邮件,但是当前检查我最终点击的节点是我创建的新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];
}

有什么想法吗?谢谢!

0 个答案:

没有答案