我有一个使用物理的简单SpriteKit游戏。用Swift编写,在iOS8模拟器中运行良好。 节点停在physicsworld边缘。
但是当在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 :(得分:0)
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
}
}
答案 1 :(得分:0)
终于搞定了!
更新了Yosemite 10.10.1和Xcode 6.1.1,创建了一个新项目。很奇怪,但现在效果很好。