ios - SKPhysicsJoint 删除节点之间的连接线

标签 ios swift sprite-kit skphysicsjoint

我有这段代码,我连接两个节点,一切都按预期工作。问题是我想删除节点之间的连接蓝线(附图供引用)。我该怎么做?

   //This function creates a player sprite node and place it on screen 

   func addPlayer () {
        player = SKShapeNode(circleOfRadius: 30)
        player.position = CGPoint(x: playableArea.midX, y: playableArea.midY - 600)
        player.fillColor = UIColor.black
        player.strokeColor = UIColor.white
        player.lineWidth = 4
        player.physicsBody = SKPhysicsBody(circleOfRadius: 30)
        player.physicsBody?.affectedByGravity = false
        player.physicsBody?.isDynamic = false
        player.name = "characterColor"
        addChild(player)
    }

//This function creates second node and attach it as tail of player node and also joint player and tail node
    func addTail () {
        tail = SKShapeNode(circleOfRadius: 25)
        tail.position = CGPoint(x: player.position.x, y: player.position.y - 60)
        tail.physicsBody = SKPhysicsBody(circleOfRadius: 25)
        tail.fillColor = UIColor.black
        addChild(tail)
        let joint = SKPhysicsJointPin.joint(withBodyA: player!.physicsBody!, bodyB: tail.physicsBody!, anchor: player.position)

        joint.shouldEnableLimits = true
        joint.lowerAngleLimit = 0
        joint.upperAngleLimit = 0
        joint.frictionTorque = 0.1
        physicsWorld.add(joint)
    }

enter image description here

最佳答案

在你的 GameViewController 中,你有 view.showPysics = true 这用于调试你的物理对象,但是当你不想再看到它时,你需要将其关闭

您还将帧速率和节点计数设置为 true

view.showsFPS = true 
view.showsNodeCount = true

只需将它们设置为 false 即可不再显示它们

关于ios - SKPhysicsJoint 删除节点之间的连接线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61882919/

相关文章:

ios - 寄存器有什么问题(_ :forCellWithReuseIdentifier:) on UICollectionView?

iphone - Apple App Store 上的应用程序提交

ios - 在 Swift 3 中访问子项时父项的导航栏变亮

ios - SwiftUI,iOS : How to access public function inside @main struct from custom internal View?

ios - 如何通过 ease in 和 ease out 创造更自然的跳跃?

sprite-kit - SpriteKit 如何创建和过渡到不同的场景

c# - 未经授权的访问异常 : Access to the path [ iOS/Unity3D ]

ios - 在 Button Swift 中通过标签发送行和部分

swift - 如何将变量的值设置为在日期选择器中选择的小时值

swift - 应用程序激活后,让场景中的粒子保持暂停状态