我试图使用
我在创建
以下是代码:
我收到的Xcode错误是
请指导我的代码哪里出了问题。
谢谢。
SKPhysicsJointPin
在下面截图中标记为绿点的anchorPoint
来连接两个SKSpriteNode
,稍后我想在object2上启用physicsBody!.dynamic = true
来获得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错误是
![enter image description here](https://istack.dev59.com/YdbXW.webp)