1

请帮助我抽象接触开始的方法。我在现场有这个方法,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
}
4

1 回答 1

0

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

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

于 2014-03-17T19:10:30.280 回答