I am developing a game for iOS using SceneKit
. When I want to set a skybox to the scene I get an error:
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"),
]
Error: Cannot assign a value of type [UIImage?] to a value of type AnyObject!
I tried to cast the array to a NSArray
or an AnyObject
array but that doesn't work.
Could anyone help me?
contents
is of type [AnyObject!]
; so, the following should work:
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!,
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.