【发布时间】:2015-03-30 12:07:18
【问题描述】:
所以基本上在我的游戏中我需要扔东西。到目前为止,我有一个精灵,它可以拖动但不能扔。游戏的想法是抛出一个精灵与另一个精灵碰撞。我想要我们称之为 testNode 的精灵,移动用户扔它的位置
意思是,当我释放精灵时,我希望它继续朝着我移动它的方向前进。我花了很长时间试图解决这个问题,但我做不到。我正在为 iOS 8+ 使用 SpriteKit。如果有人可以帮忙,请做。
我看到了一个视频,但它是与 GameSalad 相关的,这是另一个故事。你可以看看
(如果您可能需要进一步联系,请回复)
import Foundation;
import SpriteKit;
class Level:SKScene {
TestNode:Test? //Test is a class I made
//Removed the update and touches began due to it being irrelevant to what I need help with.
override func didMoveToView(view: SKView){
testNode = Fruit(imageNamed: "apple_idle")
testNode?.position = CGPointMake(60, 294)
testNode?.xScale = 0.5
testNode?.yScale = 0.5
self.addChild(testNode!)
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
var nodeTouched = SKNode()
var currentNodeTouched = SKNode()
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
nodeTouched = self.nodeAtPoint(location)
testNode?.position = location
}
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
var touch: UITouch = touches.anyObject() as UITouch
var location: CGPoint = touch.locationInNode(self) as CGPoint
}
【问题讨论】:
标签: ios swift sprite-kit