【发布时间】:2016-05-05 20:44:04
【问题描述】:
如果你在熟悉我想要做的事情之前玩过愤怒的小鸟或任何台球游戏,基本上我想要的是:
1- 在 touchesMoved 中画一条线,这样玩家就可以知道他瞄准的方向。
2- 我希望线条在碰到其他物体时反射到正确的方向。 到目前为止,我有这个:
更新:
var ref = CGPathCreateMutable()
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let location = touch.locationInNode(self)
let path = CGPathCreateMutable()
CGPathMoveToPoint(ref, nil, position.x - 100 , position.y - 100 )
CGPathAddLineToPoint(ref, nil, -location.x, -location.y)
line.removeFromParent()
line.path = ref
line.strokeColor = UIColor.redColor()
line.lineWidth = 20
line.antialiased = true
line.fillColor = UIColor.blueColor()
addChild(line)
}
}
我添加了 - before 位置,以便在节点前面绘制线,从而提供更好的瞄准感,但这给我留下了两个问题:
1- 我希望线在节点前面有一个限制,但同时,我希望它的末端是当前的触摸位置。 (基本上,我希望它通过节点)
2- 我仍然不知道如何让它在撞到墙壁或其他东西时反射到直角,这样它就可以知道节点会从墙上反弹。
【问题讨论】:
-
我不是 Sprite-kit 甚至 Swift 专家,但看起来您需要改变 SKShapeNode 对象而不是构造一个新对象。
标签: swift sprite-kit line cgpath skshapenode