首先,我很抱歉我的英语,我不会说得很好,但我觉得你能理解我;) 我有一个网格(5x5),在这个网格中,有一个球,它是网格的一个子,因为用户可以旋转网格,所以球必须跟随其相对于网格的位置。 当用户向下滑动时,球通过网格下方的框移动,但是球的位置相对于网格。当用户向下滑动时,球移动到底部,但是当用户每个示例向右旋转网格并向下滑动时,球向左移动,因为球的位置是相对于网格而不是自身位置
override func didMoveToView(view: SKView) {
/// GRID ///
grid.anchorPoint = CGPointMake(0.5, 0.5)
grid.position = CGPointMake(self.size.width / 2, self.size.height / 2)
grid.size.width = self.size.width * 0.8
grid.size.height = grid.size.width
grid.zPosition = 10
self.addChild(grid)
/// BALL ///
ball.anchorPoint = CGPointMake(0.5, 0.5)
ball.size.width = grid.size.width / 5
ball.size.height = ball.size.width
ball.position = CGPointMake(0, 0) // THE BALL IS AT THE CENTER OF THE GRID
grid.addChild(ball)
// SWIPE DOWN DETECTION
let swipeDown:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipeDown:"))
swipeDown.direction = .Down
view.addGestureRecognizer(swipeDown)
}
func swipeDown(send:UISwipeGestureRecognizerDirection) {
let moveAction = SKAction.moveBy(CGVectorMake(0, -grid.size.height / 5), duration: 0.1)
ball.runAction(moveAction)
}
我怎样才能让球每次都向下移动?