简体   繁体   English

通用应用程序背景SpriteKit

[英]Universal app background SpriteKit

I'm working on universal game (iPhone and iPad) with SpriteKit and I have issue with background size. 我正在使用SpriteKit开发通用游戏(iPhone和iPad),但背景尺寸有问题。 I created image size 2048x1536 and more image for iPhone devices in size 1136x852 and still the background is cropped on iPhone. 我为2048x1536的图像创建了图像,并为iPhone设备创建了1136x852的图像,但在iPhone上仍然裁剪了背景。 How can I fix it? 我该如何解决?

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: 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: iPhone 6 Plus: 裁剪背景

iPad Pro: iPad Pro: 适应屏幕

iPhone 4s: iPhone 4s: 裁剪背景

Assets file: 资产文件: @ 1x大小为2048x1536,@ 3x大小为1136x852

@1x size is 2048x1536 and @3x is 1136x852 The sense scale is .AspectFill with .ResizeAll the position of SKSprtieNode it not like what I want. @ 1x的大小是2048x1536,@ 3x的大小是1136x852。感知范围是.AspectFill.ResizeAll的位置,它不符合我的需求。 Thanks! 谢谢!

I tried to split the image to parts but still is cropped I think is happen because the iPhone 6 plus screen size is 736x414 and the scene size is 1024x768, and if I change the scene to the current device I need to position the sprites for each screen 我试图将图像拆分为多个部分,但仍然被裁剪,因为iPhone 6 plus屏幕尺寸为736x414,场景尺寸为1024x768,如果我将场景更改为当前设备,则需要为每个设备放置精灵屏幕 在此处输入图片说明

The devices's screen size ratios are different, and one will have to stretch dimensions to fit the screen, and this may look weird. 设备的屏幕尺寸比率不同,并且必须拉伸尺寸以适合屏幕,这看起来很奇怪。 But you can use .Fill if you are sure you like this option. 但是,如果确定您喜欢此选项,则可以使用.Fill。 The smoothest alternative is to remain using .AspectFill and create an image for each screen dimension. 最流畅的选择是保留使用.AspectFill并为每个屏幕尺寸创建一个图像。 Be creative! 有创造力! Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM