Swift 触摸开始更新每一帧
我正在做一个有按钮的游戏:当按下按钮时,玩家向前移动。松开按钮时,播放器停止移动 现在我可以用touchesbeated和touchesend功能实现这一点,但这不是我想要的,因为我要添加更多按钮并启用多点触摸,必须有一种更简单的方法Swift 触摸开始更新每一帧,swift,sprite-kit,touch,touchesbegan,Swift,Sprite Kit,Touch,Touchesbegan,我正在做一个有按钮的游戏:当按下按钮时,玩家向前移动。松开按钮时,播放器停止移动 现在我可以用touchesbeated和touchesend功能实现这一点,但这不是我想要的,因为我要添加更多按钮并启用多点触摸,必须有一种更简单的方法 有人知道怎么做吗?如何在swift中检索触摸位置 override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { let touch = touches.anyObject()!
有人知道怎么做吗?如何在swift中检索触摸位置
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject()! as UITouch
let location = touch.locationInView(self)
}
您可以对所有其他功能执行相同的操作这里是Objective-C的答案,尽管强烈建议您熟悉画面、屏幕上的位置、图层属性等,因为此解决方案可以检测到用户触摸和屏幕中元素位置之间的一致性(我说的是肖像画、风景画、动画等等)。 希望能有帮助
- (无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件{
UITouch*touch=[触摸任何对象]; CGPoint-touchLocation=[touch-locationInView:self.view]
}if (CGRectContainsPoint(aViewForExample.frame, touchLocation)){ //the user has touched within this element, so what's next? }