如何通过向左滑动将 Sprite 移动到左侧,通过向右滑动将 Sprite 向右移动等等?
如果我向左滑动,我的 Sprite 会向左移动 20 点。我正在使用 SpriteKit 和 Swift。
谢谢! @jonogilmour
我是这样解决的:
let right = SKAction.moveByX(64, y: 0, duration: 0.6)
let left = SKAction.moveByX(-64, y: 0, duration: 0.6)
let up = SKAction.moveByX(0, y: 64, duration: 0.6)
let down = SKAction.moveByX(0, y: -64, duration: 0.6)
func swipedRight(sender:UISwipeGestureRecognizer){
player.runAction(right)
}
func swipedLeft(sender:UISwipeGestureRecognizer){
player.runAction(left)
}
func swipedUp(sender:UISwipeGestureRecognizer){
player.runAction(up)
}
func swipedDown(sender:UISwipeGestureRecognizer){
player.runAction(down)
}
override func didMoveToView(view: SKView) {
let swipeRight:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedRight:"))
swipeRight.direction = .Right
view.addGestureRecognizer(swipeRight)
let swipeLeft:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedLeft:"))
swipeLeft.direction = .Left
view.addGestureRecognizer(swipeLeft)
let swipeUp:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedUp:"))
swipeUp.direction = .Up
view.addGestureRecognizer(swipeUp)
let swipeDown:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedDown:"))
swipeDown.direction = .Down
view.addGestureRecognizer(swipeDown)
............
关于ios - 如何使用滑动手势移动 Sprite ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26878185/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |