SceneKit场景背景内容UIImage数组错误

时间:2015-08-27 22:42:29

标签: ios swift uiimage swift2 scenekit

我正在使用SceneKit为iOS开发游戏。当我想将天空盒设置为场景时,我收到一个错误:

var path = "skyboxes.scnassets/skybox"
self.scene!.background.contents = [
        UIImage(named: path+"_right.png"),
        UIImage(named: path+"_left.png"),
        UIImage(named: path+"_top.png"),
        UIImage(named: path+"_bottom.png"),
        UIImage(named: path+"_front.png"),
        UIImage(named: path+"_back.png"),
    ]
  

错误:无法将类型[UIImage?]的值分配给type的值   AnyObject!

我尝试将数组转换为NSArrayAnyObject数组,但这不起作用。

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

contents的类型为[AnyObject!];所以,以下应该有效:

scene!.background.contents =
[
    UIImage(named: path+"_right.png") as UIImage!              
    UIImage(named: path+"_left.png") as UIImage!,
    UIImage(named: path+"_top.png") as UIImage!,
    UIImage(named: path+"_bottom.png") as UIImage!,
    UIImage(named: path+"_front.png") as UIImage!,
    UIImage(named: path+"_back.png") as UIImage!,
]