通过点击触摸moking精灵不要轻扫swift

时间:2016-01-27 20:42:45

标签: ios swift sprite-kit touch

我的代码中有一个块,只有点击屏幕才能移动精灵。当我向上或向下滑动时,我想有这种行为。这是我的代码

import random

my_randoms = random.sample(xrange(100), 10)        
test = pd.DataFrame(my_randoms,columns = ["x"])

1 个答案:

答案 0 :(得分:1)

使用以下代码替换 touchesBegan

// Store the start touch position
let yTouchCurrentPosition = 0.0
let yTouchDistance = 0.0
let yTouchStartPosition = 0.0
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches {
        yTouchStartPosition = touch.locationInNode(self).y
    }
}

// Calculate the distance of the touch movement
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches {
        yTouchCurrentPosition = touch.locationInNode(self).y
        yTouchDistance = yTouchStartPosition - yTouchCurrentPosition
    }
}

// Reset all movement states and move sprite
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    yTouchCurrentPosition = 0.0
    yTouchDistance = 0.0
    yTouchStartPosition = 0.0

    let moveAction = SKAction.moveToY(CGPoint(porker.guy.location.x, porker.guy.location.y + yTouchDistance), duration: 0.5)
    moveAction.timingMode = SKActionTimingMode.EaseOut
    porker.guy.runAction(moveAction)
}