我目前正在完全使用SpriteKit在iOS上进行超级马里奥模仿。在此游戏中,我创建了由不同的方块组成的墙,出于某种原因,即使实际上没有空间可以站立,玩家也可以站在这些方块之间。 (请参见下图)
playerSprite正在使用精确的碰撞检测,并且具有矩形的物理主体。
这些块不使用精确的碰撞检测,而是一个完美的正方形。
以下是有关玩家物理身体的代码:
func setupPhysics() {
self.physicsBody!.mass = 0.02275555580854416
self.physicsBody!.allowsRotation = false
self.physicsBody!.usesPreciseCollisionDetection = true
self.physicsBody!.categoryBitMask = CollisionTypes.player.rawValue
self.physicsBody!.collisionBitMask = CollisionTypes.brickBlock.rawValue | CollisionTypes.questionMarkBlock.rawValue | CollisionTypes.groundBlock.rawValue | CollisionTypes.solidBlock.rawValue | CollisionTypes.enemy.rawValue
self.physicsBody!.contactTestBitMask = CollisionTypes.brickBlock.rawValue | CollisionTypes.questionMarkBlock.rawValue | CollisionTypes.groundBlock.rawValue | CollisionTypes.solidBlock.rawValue | CollisionTypes.coin.rawValue | CollisionTypes.playerDetectionBlock.rawValue | CollisionTypes.enemy.rawValue
}
以下是有关块的代码:
self.size = CGSize(width: 16, height: 16)
self.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 16, height: 16))
self.physicsBody!.isDynamic = false
self.texture = SKTexture(imageNamed: "Solid Block")
self.texture!.filteringMode = .nearest
self.name = "SolidBlock"
self.position = position
self.physicsBody!.categoryBitMask = CollisionTypes.solidBlock.rawValue
self.physicsBody!.contactTestBitMask = CollisionTypes.player.rawValue
self.blendMode = .replace
感谢您已经帮助我!
如果您需要更多信息,请告诉我。