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

标签 swift sprite-kit apple-tv

我有一个名为 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/

相关文章:

ios - 如何在 Swift 中创建一个使用 "self"的全局变量

sprite-kit - Spritekit 跟随触摸点的线

ios - UICollectionViewCell 到 tvOS 中的 UIButton 焦点

swift - Word "func"有破折号下划线但没有错误

ios - 只有字母表、没有数字、没有大写字母、没有空格键的 UITextfield 键盘?

ios - Storyboard本地化在运行时 swift

swift - 如何在 tvos 中的 TabBar 项目上全屏播放视频

ios - Xcode模拟器10.5寸表行错位

Swift 2,SpriteKit,我在从父节点删除节点时遇到问题

swift - 编程式滚动 Apple TV 轻拂单元格