gpt4 book ai didi

swift - Apple TV - Sprite 套件中未显示图像

转载 作者:行者123 更新时间:2023-11-30 12:26:29 26 4
gpt4 key购买 nike

我有一个名为 background.png 的图像。我尝试将它从 SKS 文件添加到我的场景中,它在 xcode 中显示正常,但在模拟器中,根本没有图像显示。然后,我尝试通过代码来完成此操作,但即使如此,也没有任何显示。另外,我在控制台中没有收到任何错误消息,表明未找到图像。屏幕完全黑了。这是我的代码:

var background = SKSpriteNode(imageNamed: "background.png")
background.size.width = (background.size.width * frame.height) / background.size.height
background.size.height = frame.size.height
background.position.x = (background.size.width / 2)
background.position.y = frame.midY
background.zPosition = 0

let moveAnimation = SKAction.move(by: CGVector(dx: -background.size.width, dy: 0), duration: 10)
let shiftAnimation = SKAction.move(by: CGVector(dx: background.size.width, dy: 0), duration: 0)
let animateForever = SKAction.repeatForever(SKAction.sequence([moveAnimation, shiftAnimation]))
background.run(animateForever)

self.addChild(background)

background = SKSpriteNode(imageNamed: "background.png")
background.size.width = (background.size.width * frame.height) / background.size.height
background.size.height = frame.size.height
background.position.x = (background.size.width / 2)*3
background.position.y = frame.midY
background.zPosition = 0
background.run(animateForever)

self.addChild(background)

background = SKSpriteNode(imageNamed: "background.png")
background.size.width = (background.size.width * frame.height) / background.size.height
background.size.height = frame.size.height
background.position.x = -(background.size.width / 2) + 2
background.position.y = frame.midY
background.zPosition = 0
background.run(animateForever)

self.addChild(background)

如有任何帮助,我们将不胜感激。

最佳答案

问题是图像尺寸太大。图像的大小为 8000 x 4000 像素。我将其更改为 4000 x 2000,一切正常。

关于swift - Apple TV - Sprite 套件中未显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44136996/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com