我正在使用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!
我尝试将数组转换为NSArray
或AnyObject
数组,但这不起作用。
有人可以帮助我吗?
答案 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!,
]