【发布时间】:2015-12-31 15:15:38
【问题描述】:
我正在使用 Sprite Kit 制作游戏,我希望能够在框沿屏幕移动时拖放它们。
以下是代码的要点:我在计时器上生成框,然后它们在屏幕上向下移动。
override func didMoveToView(view: SKView) {
let timer = NSTimer.scheduledTimerWithTimeInterval(2.0, target: self, selector: Selector("spawnBox"), userInfo: nil, repeats: true)
}
func spawnBox() {
/* Set up the box */
addChild(box)
let boxMoveDown = SKAction.moveToY(-100, duration: 5.0)
let actionDone = SKAction.removeFromParent()
box.runAction(SKAction.sequence([boxMoveDown, actionDone]))
}
但问题是我怎样才能在不影响所有其他“孩子”的情况下移动我正在触摸的特定孩子?我知道,目前,我每次生成一个盒子时都是完全相同的,所以当我设置单个孩子的位置时,我无法具体说明。
这是我的 touchesBegan 和 touchesMoved 函数中的内容
if let touch = touches.first {
let location = touch.locationInNode(self)
let objects = nodesAtPoint(location) as [SKNode]
if objects.contains(nodeAtPoint(location)) && nodeAtPoint(location).name == "box" {
box.position = location
box.removeAllActions()
}
}
-box.position = location 是什么
需要改变。
希望你能理解我的想法。我试图将包含的代码保留在必要的范围内。我对 Sprite Kit 很陌生,你可能知道。
【问题讨论】:
-
当您检测到某个节点被选中时,您需要删除使该节点向下移动的
SKAction。
标签: swift sprite-kit