图像没有显示在苹果电视 - 精灵套件

时间:2017-05-23 14:02:17

标签: 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)

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

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