我正在尝试在下面的屏幕截图中SKSpriteNode
使用标记为绿点的SKPhysicsJointPin
at连接两个 。anchorPoint
后来我想physicsBody!.dynamic = true
在object2上启用以获取object2的“摆动动画”。
我一开始在创建时遇到困难,SKPhysicsJointPin
即使我在 Xcode 中没有遇到错误,它也无法编译。
这是代码:
import SpriteKit
class GameScene: SKScene, SKPhysicsContactDelegate {
let object1 = SKSpriteNode(imageNamed: "white")
let object2 = SKSpriteNode(imageNamed: "black")
override func didMoveToView(view: SKView) {
// Setup background image
self.backgroundColor = UIColor(hex: 0x60c0f3)
// Setup physics body to the scene (borders)
self.physicsBody = SKPhysicsBody (edgeLoopFromRect: self.frame)
// Change gravity settings of the physics world
self.physicsWorld.gravity = CGVectorMake(0, -9.8)
self.physicsWorld.contactDelegate = self
//===========================================
// White object properties
object1.physicsBody = SKPhysicsBody(rectangleOfSize: object1.frame.size)
object1.physicsBody!.dynamic = false
object1.position = CGPointMake(size.width/2 - object1.size.width/2, size.height/2)
// Black object properties
object2.physicsBody = SKPhysicsBody(rectangleOfSize: object2.frame.size)
object2.physicsBody!.dynamic = true
object1.anchorPoint = CGPointMake(0, 0)
object2.position = CGPointMake(size.width/2 + object2.size.width + 2, size.height/2 + object2.size.height/2)
// Create joint between two objects
var myJoint = SKPhysicsJointPin.jointWithBodyA(object1.physicsBody, bodyB: object2.physicsBody, anchor: CGPoint(x: CGRectGetMaxX(self.object1.frame), y: CGRectGetMaxY(self.object2.frame)))
self.physicsWorld.addJoint(myJoint)
self.addChild(object1)
self.addChild(object2)
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
我得到的 Xcode 错误是
请告知我的代码有什么问题。谢谢你。