在SKView上设置渐变背景会隐藏所有内容

时间:2016-03-11 17:58:27

标签: swift sprite-kit gradient z-order

我试图在SKView后面创建一个Gradient背景,并将我的游戏资产放在它上面。

所有的艺术作品,showsFPS和showsNodeCount都被隐藏了。

我认为它与页面上的zPriority项有关;但它已经零,所以我不知道为什么隐藏它。

查看控制器

override func viewDidLoad() {
        super.viewDidLoad()

        /* Set gradient bg color */
        let layer : CAGradientLayer = CAGradientLayer()
        layer.frame.size = self.view.frame.size
        layer.frame.origin = CGPointMake(0.0,0.0)

        let color0 = UIColor(red:58.0/255, green:123.0/255, blue: 162.0/255, alpha:1).CGColor
        let color1 = UIColor(red:51.0/255, green:110.0/255, blue: 149.0/255, alpha:1).CGColor
        let color2 = UIColor(red:40.0/255, green:91.0/255, blue: 130.0/255, alpha:1).CGColor
        let color3 = UIColor(red:36.0/255, green:85.0/255, blue: 122.0/255, alpha:1).CGColor
        let color4 = UIColor(red:27.0/255, green:70.0/255, blue: 108.0/255, alpha:1).CGColor
        let color5 = UIColor(red:13.0/255, green:51.0/255, blue: 87.0/255, alpha:1).CGColor
        let color6 = UIColor(red:3.0/255, green:34.0/255, blue: 72.0/255, alpha:1).CGColor

        layer.colors = [color0,color1,color2,color3, color4, color5, color6]
        view.layer.insertSublayer(layer, atIndex: 0)


        if let scene = GameScene(fileNamed: "GameScene") {

            // Configure the view.
            let skView = self.view as! SKView
            skView.showsFPS = true
            skView.showsNodeCount = true

            /* Sprite Kit applies additional optimizations to improve rendering performance */
            skView.ignoresSiblingOrder = true

            /* Set the scale mode to scale to fit the window */
            scene.scaleMode = .AspectFill


            skView.presentScene(scene)
        }
    }

场景本身只有1个艺术资产

class GameScene: SKScene {

    override func didMoveToView(view: SKView) {
        /* Setup your scene here */

        let texture:SKTexture = SKTexture(imageNamed: "table")
        texture.filteringMode = SKTextureFilteringMode.Nearest


        // Table sprite
        let tableSprite = SKSpriteNode(texture: texture)
        tableSprite.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))


        self.addChild(tableSprite)
    }

// ...   
}

但是FPS计数,节点数或表精灵都没有显示。

我做错了什么?

由于

0 个答案:

没有答案