[英]SpriteKit touches
please help me with abstract touches began method. 请以抽象的手法开始帮助我。 I have this method at scene, VZChurch it's SKSpriteNode.
我在现场有这种方法,VZChurch是SKSpriteNode。 Is there way to transfer touches began method inside Subclass of SKSpriteNode, because i think that 5-6 if else statement not shine decision, so i try to found way to migrate touches began method in every subclass of SKSpriteNode
SKSpriteNode的子类内部是否有转移触摸开始方法的方法,因为我认为5-6否则语句不能发光,因此我尝试在SKSpriteNode的每个子类中找到迁移触摸开始方法的方法
- (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
}
The best way to avoid what you're asking is to subclass an SKNode
(or SKSpriteNode
) for each node. 避免询问的最好方法是为每个节点
SKSpriteNode
一个SKNode
(或SKSpriteNode
)子类。 This then allows you handle the touchesBegan
inside the subclassed node. 然后,这使您可以处理子类节点内部的
touchesBegan
。
So just subclass a SKNode (or SKSpriteNode since VZChurch is a sprite) and handling the touchesBegan
in VZChurch
's it it's own methods file. 因此,只需将SKNode子类化(或者因为VZChurch是一个Sprite,就可以继承SKSpriteNode)并处理
VZChurch
的touchesBegan
,这是它自己的方法文件。 Then if you have other SKSprites, do the same thing, subclass each sprite and handle the touchesBegan
inside their respective subclassed methods file. 然后,如果您还有其他SKSprite,请执行相同的操作,将每个Sprite子类化,并处理其各自子类化方法文件中的
touchesBegan
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.