This has been addressed in How do I drag and drop a sprite in Swift 3.0?.
But... this this gives me a bad lag between finger and sprite. With Xcode, try creating a from-scratch iOS Game app, using SpriteKit. Comment out all the touch-handling code and replace it with the following
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
let t = touches.randomElement()!
self.spinnyNode?.position = t.location(in:self)
}
(You will also have to do a few obvious things to make the spinnyNode
stay visible.)
The result is shown here at http://andrewduncan.net/drag/drag2.m4v
The following posts all recommend the same approach — setting the position
in touchesMoved()
.
- How do I drag and drop a sprite in Swift 3.0? (The aforementioned.)
- SKSpriteNode drag movement by touch
- how to throw SKSpriteNode?
- http://mammothinteractive.com/touches-and-moving-sprites-in-xcode-spritekit-swift-crash-course-free-tutorial
- Choppy dragging in SpriteKit game (asked but not answered)
- https://www.youtube.com/watch?v=YjvrjjvrIYU
- https://www.youtube.com/watch?v=MPhdAhJFxmA
- https://www.youtube.com/watch?v=gmlc38rD8cc
I have implemented a bletcherous hack (see Using SpriteKit inside UIKit) where I have small SKViews
(one per sprite) that are quickly draggable using UIGestureRecognizers
. But each view needs its own SKScene
, which seems backward (or orthogonal?) to the original intent.