如何建模不是矩形或圆形的精灵节点

时间:2015-02-06 17:55:51

标签: swift ios8 sprite-kit skspritenode

嗨我的游戏中有一些三角形形状需要一个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)

1 个答案:

答案 0 :(得分:1)

您可以将SKTexture设置为SKPhysicsbody参数:

randomMountain.physicsBody = SKPhysicsBody(texture: mountainTexture, size: mountainTexture.size)