【发布时间】:2018-04-04 13:51:51
【问题描述】:
由于我在 spritekit 中工作,我决定不使用 UIScrollview,因为据我所知,它很难实现。相反,根据在线研究,我决定创建一个SKNode,并将我所有的精灵添加为SKNode 的子代。从那里,在touchesMoved 函数中,我移动了我的SKNode 以复制UIScrollview。这部分工作完美。 SKNode 的所有精灵都在我滚动模拟动作的任何地方移动,但是,如果我打印出 -> print(spriteA.position),则该值不会从它的初始位置改变。当我打印出print(SKNode.position) 时,该值确实从它的初始位置发生了变化。
blueBottle = SKSpriteNode(texture: SKTexture(imageNamed: "Bottle"), size: CGSize(width: 0.065*size.height, height: 0.2*size.height))
blueBottle.position = CGPoint(x: 0.8*size.width, y: topShelf.position.y + 0.5*topShelf.size.height + 0.5*blueBottle.size.height)
blueBottle.name = "Play"
blueBottle.zPosition = Layer.ui.rawValue
moveableNode.addChild(blueBottle)
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch: AnyObject in touches {
let location = touch.location(in: self)
touchPoint = location
secondLocation = location
}
moveableNode.position.y = touchPoint.y - (firstLocation.y - moveableNodePos.y)
print(moveableNode.position.y)
print(bluebottle.position.y)
}
这对我来说很奇怪,因为精灵成功移动了,但是位置没有更新......我唯一能想到的是精灵没有正确附加到SKNode?
【问题讨论】:
标签: swift sprite-kit position sknode touchesmoved