SKAction.reach不会定向已移动的子节点

时间:2017-10-06 20:25:06

标签: ios swift sprite-kit

我为此问题道歉,因为我对Swift,SpriteKit和游戏开发都很陌生。

我正在玩SpriteKit中的反向运动功能。具体来说,我正在尝试使用SKAction.reach操作将节点定向为指向另一个节点。

我遇到的挑战是当我想要定位到子节点时。具体来说,我有一个非常简单的代码,我正在我的SKScene类中玩:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    // Already defined: parent_a, parent_b, child_a, child_b (all SKNode)
    // with child_a having parent of parent_a
    // and child_b having parent of parent_b

    // Purposely only change the coordinate of the parent item
    parent_b?.position = CGPoint(x:parent_b!.position.x,y: parent_b!.position.y + 50)

    // WHen this line is uncommented, then I get the WRONG behaviour: the "A" elements point at the original location
    child_a?.run(SKAction.reach(to: child_b!, rootNode: parent_a!, duration: 0.5))
    // But this line "works" CORRECTly; the "A" elements continue to point up at the moving object (note: I really want to orient to the child)
    //child_a?.run(SKAction.reach(to: parent_b!, rootNode: parent_a!, duration: 0.5))
}

基本上,当我点击屏幕时,我将parent_b节点向上移动到屏幕上。在视觉上,child_b节点向上移动。如果我有第一行使用,我的“A”对象指向“B”对象的原始位置。如果我使用第二行,则“A”将定向并指向“B”,因为我将其移动得越来越高。我的目标是始终让“A”朝向“B”。

我不确定我理解为什么会发生这种情况或如何获得我想要的行为。我可以理解“孩子”物体相对于父母的位置,但我不知道如何让孩子的物体相互定位。

非常感谢您的帮助!

0 个答案:

没有答案