我发现了这个问题,这听起来类似于StackOverflow_24965533但接受的答案在 9.3 中不起作用。
我所看到的示例: 此处链接到图像
我的代码:
func addtopMachete() {
let topMacheteTexture = SKTexture(imageNamed: "machete.png")
topMacheteSwing = SKSpriteNode(texture: topMacheteTexture)
topMacheteSwing.name = "topMacheteSwing_Node"
topMacheteSwing.anchorPoint = CGPoint(x: 0.0, y: 0.0)
let newX = topMacheteSwing.position.x
let newY = topMacheteSwing.position.y + (hero.size.height / 2)
let newLocation = CGPointMake(newX, newY)
topMacheteSwing.position = newLocation
topMacheteSwing.zRotation = -0.45
let movetopMacheteSwing = SKAction.rotateToAngle(2.75, duration: 3)
let removetopMacheteSwing = SKAction.removeFromParent()
let moveAndRemovetopMacheteSwing = SKAction.sequence([movetopMacheteSwing, removetopMacheteSwing])
topMacheteSwing.runAction(moveAndRemovetopMacheteSwing)
topMacheteSwing.physicsBody = SKPhysicsBody(rectangleOfSize: topMacheteSwing.size, center: CGPointMake(topMacheteSwing.size.width / 2, topMacheteSwing.size.height / 2))
topMacheteSwing.physicsBody!.dynamic = false
topMacheteSwing.physicsBody!.affectedByGravity = false
topMacheteSwing.physicsBody!.categoryBitMask = ColliderType.macheteContact.rawValue
topMacheteSwing.physicsBody!.contactTestBitMask = ColliderType.monsterContact.rawValue | ColliderType.monster2HPContact.rawValue | ColliderType.riotShieldContact.rawValue
topMacheteSwing.physicsBody!.usesPreciseCollisionDetection = true
let topMacheteJoint = SKPhysicsJointFixed.jointWithBodyA(hero.physicsBody!, bodyB: topMacheteSwing.physicsBody!, anchor: CGPoint(x: CGRectGetMaxX(hero.frame), y: CGRectGetMaxY(hero.frame)))
hero.addChild(topMacheteSwing)
self.physicsWorld.addJoint(topMacheteJoint)
}
英雄测试 UI 只是灰色圆圈,当他被推动时,我希望子节点“topMacheteSwing”与他一起移动。我认为将它们固定在一起可以做到这一点,但事实并非如此。
非常感谢您的帮助。