SpriteKit节点物理不能按预期工作

时间:2015-10-23 23:28:47

标签: ios swift sprite-kit

我有3个圆圈在屏幕上弹跳,应该同时下降和反弹。 使用iPhone 4 iOS 7可以正常工作,但使用iPod Touch 6G iOS 9.1或iPhone模拟器iOS 8.4时,第三个圆圈的dy速度不同。为什么会发生这种情况,我该如何解决?屏幕截图如下。

import SpriteKit

class GameScene: SKScene {

let circleCategory = UInt32(1 << 1)
let boundaryCategory = UInt32(1 << 2)

override func didMoveToView(view: SKView) {

    self.physicsWorld.gravity = CGVectorMake(0.0, -5.8)
    self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
    self.physicsBody?.categoryBitMask = boundaryCategory

    initCircles()

}

func initCircles(){


    let circleAXPostion = CGRectGetMidX(self.frame) - self.frame.width/3
    let circleCXPostion = CGRectGetMidX(self.frame) + self.frame.width/3
    let yPosition = CGRectGetMinY(self.frame) + 425

    for i in 1...3{

        let circleA = SKShapeNode()
        circleA.name = "Circle\(i)"
        circleA.path = CGPathCreateWithRoundedRect(CGRectMake(-12, -12, 24, 24), 12, 12, nil)
        circleA.fillColor = UIColor.redColor()
        circleA.strokeColor = UIColor.redColor()


        var postionX:CGFloat!
        if i == 1{
            postionX = circleAXPostion
        }else if i == 2{
            postionX = CGRectGetMidX(self.frame)
        }else{
            postionX = circleCXPostion
        }
        circleA.position = CGPointMake(postionX, yPosition)
        circleA.physicsBody = SKPhysicsBody(circleOfRadius: circleA.frame.size.width/2)

        circleA.physicsBody?.categoryBitMask = circleCategory
        circleA.physicsBody?.collisionBitMask = boundaryCategory

        circleA.physicsBody?.restitution = 1.0
        circleA.physicsBody?.linearDamping = 0.01
        circleA.physicsBody?.friction = 0.0
        circleA.physicsBody?.allowsRotation = false
        circleA.physicsBody?.mass = 0.5
        circleA.physicsBody?.dynamic = true

        self.addChild(circleA)

    }



}


} 

Screenshots

0 个答案:

没有答案