(edgeLoopF​​rom)不适用于帧内的移动对象

时间:2017-06-24 12:08:05

标签: swift xcode sprite-kit

我正在寻找一种在球架内移动球的方法。我设置了一个方形spriteNode并使其physicsBody属性为边缘类型。然后我把球放进去。

我无法接触到两者之间的接触,球从框架上移开。

class GameScene: SKScene {

    let square = SKSpriteNode ()
    var ball = SKShapeNode ()


override func didMove(to view: SKView) {

    self.backgroundColor = .white

    //building the frame
    square.size = CGSize (width: self.size.width * 0.8 , height: self.size.width * 0.8)
    square.position = CGPoint (x: self.size.width / 2 , y: self.size.height / 2 )
    square.color = .orange
    square.zPosition = 2
    self.addChild(square)

    square.physicsBody = SKPhysicsBody (edgeLoopFrom: square.frame)
    square.physicsBody?.isDynamic = false
    square.physicsBody?.allowsRotation = true
    square.physicsBody?.friction = 0
    square.physicsBody?.restitution = 1
    square.physicsBody?.affectedByGravity = false
    square.physicsBody?.categoryBitMask = 1
    square.physicsBody?.contactTestBitMask = 2
    square.physicsBody?.collisionBitMask = 2

    //making the moving ball

    ball = SKShapeNode (circleOfRadius: 10)
    ball.strokeColor = .black
    ball.lineWidth = 2
    ball.fillColor = .blue
    ball.position = CGPoint (x: self.size.width / 2 , y: self.size.height/2 )

    ball.zPosition = 2
    self.addChild(ball)

    ball.physicsBody = SKPhysicsBody (circleOfRadius: 10)
    ball.physicsBody?.isDynamic = true
    ball.physicsBody?.affectedByGravity = true
    ball.physicsBody?.friction = 0
    ball.physicsBody?.restitution = 1
    ball.physicsBody?.categoryBitMask = 2
    ball.physicsBody?.contactTestBitMask = 1
    ball.physicsBody?.collisionBitMask = 1




}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    square.zRotation -= .pi/36
}

}

我甚至试图将球添加到广场但没有发生任何事情。

0 个答案:

没有答案