2015-10-12 55 views
1

试图让我的SKSpriteNode停留在使用edgeLoopF​​romRect:view.frame的只有肖像的布局框架内,并且它仅从框架的左侧反弹,仍然留下间隙....physicsBody = SKPhysicsBody(edgeLoopF​​romRect:view.frame)

试图用 “视图”,edgeLoopF​​romRect:框架,它飞走了屏幕...

任何帮助,将不胜感激..

func makeShip() { 
    let ship = playerShip 
    ship.position = CGPoint(x: frame.size.width/2, y: frame.size.height/2) 
    ship.physicsBody = SKPhysicsBody(rectangleOfSize: ship.frame.size) 
    ship.physicsBody!.dynamic = true 
    ship.physicsBody!.affectedByGravity = false 
    ship.physicsBody!.mass = 0.08 
    addChild(ship) 
} 


override func didMoveToView(view: SKView) { 

    makeShip() 
    physicsBody = SKPhysicsBody(edgeLoopFromRect: view.frame) 
    motionManager.startAccelerometerUpdates() 
} 
+0

有两个问题。你有没有尝试将'ship'物理体设置为'rectangleOfSize:ship.size'?我不确定你是否在寻找框架(随时纠正我)。并且您是否尝试过'ship.physicsBody!.usesPreciseCollisionDetection = true'以确保船舶无法通过边界弹出? – Gliderman

+0

是的,我通过binarysubstrate –

回答

1

override func didMoveToView(view: SKView)尝试添加:

let borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame) 
borderBody.friction = 0 
self.physicsBody = borderBody