2017-03-06 59 views
0

我目前工作的一个游戏SpriteKit,我需要响应移动精灵触碰(即当用户滑动或平底锅中SKView任何地方。如何复制iOS主屏幕行为?

我想盘的方向(刷卡我知道如何做到这一点),以便精灵将根据泛移动(如果用户平移或者如果用户滑动,我有一个为精灵定义的路径),iOS appdrawer中的触摸方式工作,即它响应最轻微的(也就是当你向前或向后平移时,它决定你是否要移动到下一个屏幕)

是否有任何文档?或者我已经通过了UIGestureRecognizer文档,但我一直无法找到实现我的方法t)

回答

1

我在MenuScene上使用类似的东西,我有3页设置,用户可以滚动来获取各种游戏数据。但我不想轻轻触摸屏幕,这会让用户感到震惊。因此,我只是在Touches功能中观察手指移动,并检查移动量是否大于我指定的最小移动量,并且是否大于I滚动页面。在你的情况下,你可以处理它;如果它大于最小移动量则视为平移,否则将其视为滑动

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 

    let touch: UITouch = touches.first! 
    initialTouch = touch.location(in: self.view!) 
    moveAmtY = 0 
    moveAmtX = 0 
    initialPosition = menuScroller.position 
} 

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { 

    let touch: UITouch = touches.first! 
    let movingPoint: CGPoint = touch.location(in: self.view!) 
    moveAmtX = movingPoint.x - initialTouch.x 
    moveAmtY = movingPoint.y - initialTouch.y 

    //their finger is on the page and is moving around just move the scroller and parallax backgrounds around with them 
    //Check if it needs to scroll to the next page when they release their finger 
    menuScroller.position = CGPoint(x: initialPosition.x + moveAmtX, y: initialPosition.y) 
} 

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { 

    //they havent moved far enough so just reset the page to the original position 
    if fabs(moveAmtX) > 0 && fabs(moveAmtX) < minimum_detect_distance { 
     resetPages() 
    } 

    //the user has swiped past the designated distance, so assume that they want the page to scroll 
    if moveAmtX < -minimum_detect_distance { 
     moveLeft() 
    } 
    else if moveAmtX > minimum_detect_distance { 
     moveRight() 
    } 
} 
+0

谢谢您的回应。 – Layers