有没有办法制作响应层节点?

时间:2015-02-07 05:53:43

标签: swift sprite-kit game-physics sknode

我是SpriteKit的新手,我已经找到了答案,但似乎找不到答案。

有没有办法让节点扩展到适合你所使用的设备?

现在我正在创建具有特定尺寸或比例的图层。我想做的是创建一个可扩展的矩形,将一个物理体附加到它上面,并将其作为我游戏的边界。

我目前正在做的事情:

gamescene.swift

override func didMoveToView(view: SKView) {
    let maxAspectRatio: CGFloat = 16.0 / 9.0
        let maxAspectRatioheight = size.width / maxAspectRatio
        let playableMargin: CGFloat = (size.height - maxAspectRatioheight) / 2
        let playableRect = CGRect(x: 0, y: playableMargin, width: size.width, height: size.height - playableMargin * 2)

        physicsBody = SKPhysicsBody(edgeLoopFromRect: playableRect)
}

但我也尝试过使用背景:

// declared with the other fields outside method
var background = SKSpriteNode(imageNamed: "background")

//inside didMoveToView
    let bounds = SKNode()
        bounds.physicsBody = SKPhysicsBody(edgeLoopFromRect:
            CGRect(x: 0, y: 0,
            width: background.size.width,
            height: background.size.height))
        bounds.physicsBody!.categoryBitMask = PhysicsCategory.Boundary
        bounds.physicsBody!.friction = 0
        worldNode.addChild(bounds)

任何提示都将不胜感激!

0 个答案:

没有答案