Swift physics不支持iOS7
我有一个简单的SpriteKit游戏,使用物理。用Swift编写,在iOS8模拟器中运行良好。 节点停止在physicsworld边缘 但当在iOS7上运行时,它正好跌入谷底。认为它与类别、接触和碰撞位掩码有关 有线索吗 在这里定义类别Swift physics不支持iOS7,ios7,swift,ios8,sprite-kit,skphysicsbody,Ios7,Swift,Ios8,Sprite Kit,Skphysicsbody,我有一个简单的SpriteKit游戏,使用物理。用Swift编写,在iOS8模拟器中运行良好。 节点停止在physicsworld边缘 但当在iOS7上运行时,它正好跌入谷底。认为它与类别、接触和碰撞位掩码有关 有线索吗 在这里定义类别 struct PhysicsCategory { static let None: UInt32 = 0 static let Edge: UInt32 = 0b1 // 1 static let Player: UInt32 = 0b1
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
嗯,我没有这个问题。我几乎一字不差地写了你的代码。我假设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
}
}
终于成功了
更新到Yosemite 10.10.1和Xcode 6.1.1,创建了一个新项目。奇怪,但现在效果很好。谢谢,但这根本不起作用。我没有使用SKShapeNode,playerNode是来自图像的SkSpriteNode,但我已经为PhysicsBody创建了自定义路径。-[SKShapeNode shapeNodeWithEllipseInRect:]:发送到类0x10b5aa168的无法识别的选择器。-根据文档,shapeNodeWithEllipseInRect似乎只适用于iOS8及以上版本。啊,是的。这是有道理的。ios8发布后,他们为skshapenode制作了一些新的初始值设定项。