【问题标题】:SpriteKit touchesSpriteKit 触摸
【发布时间】:2014-03-16 11:35:44
【问题描述】:

请帮助我抽象的接触开始方法。 我在现场有这个方法,VZChurch 它是 SKSpriteNode。有没有办法在 SKSpriteNode 的子类中转移 touches started 方法,因为我认为 5-6 if else 语句不亮决定,所以我尝试在 SKSpriteNode 的每个子类中找到迁移 touches started 方法的方法

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

    if ([node.name isEqualToString:@"church"]) {

        VZChurch *obj = (VZChurch *)node;
        obj.requestedAnimation = VZAnimationStateTouch;
        [obj runAnimation];
    } else if ...n iterations
}

【问题讨论】:

    标签: objective-c sprite-kit skspritenode


    【解决方案1】:

    避免你所问的最好方法是为每个节点子类化一个SKNode(或SKSpriteNode)。这允许您处理子类节点内的touchesBegan

    所以只需子类化一个 SKNode(或 SKSpriteNode,因为 VZChurch 是一个精灵)并处理 VZChurch 中的 touchesBegan 它是它自己的方法文件。然后,如果您有其他 SKSprite,请执行相同的操作,将每个 sprite 子类化并在其各自的子类方法文件中处理 touchesBegan

    【讨论】:

    • 谢谢,我已经做到了,但它不起作用,但我发现问题出在 uiscrollview 中,zPosition 更高,然后是静态视图的 zPosition)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 2016-11-03
    • 2017-03-31
    • 2021-11-28
    • 2016-11-01
    • 1970-01-01
    相关资源
    最近更新 更多