嗨我的游戏中有一些三角形形状需要一个collisionBitMask来处理联系但我无法弄清楚如何建模除了circleOfRadius或RectangleOfSize之外的physicsBody。如何制作自定义物理主体以使联系人准确无误。这是我游戏中许多不同角色/障碍的问题。
var randomNumber = arc4random() % 3
var randomMountainImage:String!
if randomNumber == 0 {
randomMountainImage = "RedMountain.png"
} else if randomNumber == 1 {
randomMountainImage = "OrangeMountain.png"
} else {
randomMountainImage = "BeigeMountain.png"
}
var mountainTexture = SKTexture(imageNamed: randomMountainImage)
var randomMountain = SKSpriteNode(texture: mountainTexture)
var maxPositionOffset = min(100, movementAmount)
randomMountain.position = CGPointMake( CGRectGetMidX(self.frame) + self.frame.width, 200 - gapHeight + CGFloat(movementAmount))
randomMountain.zPosition = 8
//here is the problem
randomMountain.physicsBody = SKPhysicsBody(rectangleOfSize: randomMountain.size)
randomMountain.physicsBody?.dynamic = false
self.addChild(randomMountain)
答案 0 :(得分:1)
您可以将SKTexture
设置为SKPhysicsbody
参数:
randomMountain.physicsBody = SKPhysicsBody(texture: mountainTexture, size: mountainTexture.size)