通用应用程序背景SpriteKit

时间:2016-05-12 21:47:01

标签: ios swift sprite-kit

我正在使用SpriteKit开发通用游戏(iPhone和iPad),我遇到背景大小问题。 我为尺寸为1136x852的iPhone设备创建了大小为2048x1536的图像和更多图像,并且仍然在iPhone上裁剪了背景。 我该如何解决?

let screenHeight = screenSize.size.height

    //Backgorund

    var dayBackground = SKSpriteNode(imageNamed:"BackgroundDay")
    dayBackground.zPosition = -1
    dayBackground.position = CGPoint(x:size.width/2, y:size.height/2)
    dayBackground.anchorPoint = CGPointMake(0.5, 0.5)
    dayBackground.size = self.frame.size

GameViewController:

     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)
    }

iPhone 6 Plus: The background is cropped

iPad Pro: Fit to screen

iPhone 4s: Cropped background

资产档案: @1x size is 2048x1536 and @3x is 1136x852

@ 1x大小为2048x1536,@ 3x大小为1136x852 感知尺度是.AspectFill.ResizeAll SKSprtieNode的位置不像我想要的那样。 谢谢!

我试图将图像分割成部分但仍然被裁剪 我认为是因为iPhone 6 plus屏幕尺寸为736x414,场景尺寸为1024x768,如果我将场景更改为当前设备,我需要为每个屏幕定位精灵 enter image description here

1 个答案:

答案 0 :(得分:0)

设备的屏幕尺寸比率不同,并且必须拉伸尺寸以适应屏幕,这可能看起来很奇怪。但如果你确定喜欢这个选项,你可以使用.Fill。最顺畅的选择是继续使用.AspectFill并为每个屏幕尺寸创建一个图像。要有创意!祝你好运!

相关问题