停止SKAction.applyForce

时间:2017-05-22 08:02:22

标签: ios swift sprite-kit skaction

我有一个在屏幕上弹跳的球,当调用函数touchesEnded时球开始反弹:

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    for touch in touches{

        let location = touch.location(in: self)

        let ballposition = CGVector.init(dx: location.x, dy: location.y - circle.position.y)

        circle.run(SKAction.applyForce(ballposition, duration: 0.3), withKey: "move")


    }}

但是,我有碰撞检测,所以当球击中一个名为bottom的节点时,我会收到通知

    if contact.bodyA.node?.name == "Bottom" && contact.bodyB.node?.name == "circle" {
            circle.removeAction(forKey: "move")
            print("Hit")

        }
    }

球在代码

中命名为圆圈

我希望动作SKAction.applyForce在发生碰撞时停止 我得到了#34; Hit&#34;这意味着检测工作正常但是 circle.removeAction(forKey:&#34; move&#34;) 不行,idk为什么。

我也试过circle.removeAllActions()

2 个答案:

答案 0 :(得分:0)

此圈子与您添加动作的圈子是否相同? 尝试W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found. I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:2 I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 2 W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000004/n/armeabi

答案 1 :(得分:0)

SKAction.applyForce方法仅对物理实体施加力。移除钥匙将停止施加力,但不会移除当前效果。要停止身体,你可以改变身体的速度向量:

 circle.physicsBody?.velocity = CGVector.zero