2014-12-08 8 views
0

물리학을 사용하는 간단한 SpriteKit 게임이 있습니다. 스위프트로 작성되었으며 iOS8 Simulator에서 훌륭하게 작동합니다. 노드가 physicsworld 가장자리에서 멈 춥니 다.신속한 물리학이 iOS7에서 작동하지 않습니다.

하지만 iOS7에서 실행하면 바로 물마루가 떨어집니다. 카테고리, 접촉 및 충돌 비트 마스크와 관련이 있다고 생각하십시오.

실마리?

struct PhysicsCategory { 
    static let None: UInt32 = 0 
    static let Edge: UInt32 = 0b1 // 1 
    static let Player: UInt32 = 0b10 // 2 
    static let Enemy: UInt32 = 0b100 // 4 
} 

설정 세계 여기에 카테고리를 정의

physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame) 
physicsWorld.contactDelegate = self 
physicsBody!.categoryBitMask = PhysicsCategory.Edge 
physicsWorld.gravity = CGVectorMake(0, -9.81) 

설정 플레이어/볼/노드

playerNode.physicsBody = SKPhysicsBody(polygonFromPath: path) 
playerNode.physicsBody!.contactTestBitMask = PhysicsCategory.Player 
playerNode.physicsBody!.dynamic = true 
playerNode.physicsBody!.mass = 0.50 
playerNode.physicsBody!.categoryBitMask = PhysicsCategory.Player 
playerNode.physicsBody!.collisionBitMask = PhysicsCategory.Enemy | PhysicsCategory.Edge 

답변

0

마지막으로 작동했습니다.

Yosemite 10.10.1 및 Xcode 6.1.1로 업데이트하여 새 프로젝트를 만들었습니다. 이상하지만 훌륭한 작품입니다.

0

흠 내가 그 문제가 아니에요. 나는 거의 당신의 코드를 그대로 썼다. playerNode가 SKShapeNode라고 가정하고 경로를 사용했습니다. polygonFromPath iOS7에서 이것을 실행 해보고 문제가 계속 발생하는지 확인해 주시겠습니까?

struct PhysicsCategory { 
    static let None: UInt32 = 0 
    static let Edge: UInt32 = 0b1 // 1 
    static let Player: UInt32 = 0b10 // 2 
    static let Enemy: UInt32 = 0b100 // 4 
} 

import SpriteKit 

class GameScene: SKScene, SKPhysicsContactDelegate { 

    let playerNode = SKShapeNode(ellipseInRect: CGRect(origin: CGPointZero, size: CGSize(width: 10, height: 10))) 

    override func didMoveToView(view: SKView) { 

     physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame) 
     physicsWorld.contactDelegate = self 
     physicsBody!.categoryBitMask = PhysicsCategory.Edge 
     physicsWorld.gravity = CGVectorMake(0, -9.81) 

     self.addChild(playerNode) 


     playerNode.position = CGPoint(x: self.size.width/2, y: self.size.height/2) 
     playerNode.physicsBody = SKPhysicsBody(polygonFromPath: playerNode.path) 
     playerNode.physicsBody!.dynamic = true 
     playerNode.physicsBody!.mass = 0.50 
     playerNode.physicsBody!.categoryBitMask = PhysicsCategory.Player 
     playerNode.physicsBody!.collisionBitMask = PhysicsCategory.Enemy | PhysicsCategory.Edge 
    } 

} 
+0

감사합니다. 그러나 이것은 전혀 작동하지 않습니다. SKShapeNode를 사용하지 않고 playerNode는 이미지의 SKSpriteNote이지만 PhysicsBody의 사용자 정의 경로를 만들었습니다. - [SKShapeNode shapeNodeWithEllipseInRect :] : 알 수없는 선택기가 0x10b5aa168 클래스에 전송되었습니다. - shapeNodeWithEllipseInRect와 같은 모양은 문서에 따라 iOS8 이상에서만 작동합니다. –

+0

아아. 그건 의미가 있습니다. 그들은 ios8이 나왔을 때 skshapenode를위한 새로운 초기화 프로그램을 만들었습니다. – hamobi