I have an UIView that i want to add a SKScene to. In the step were i declare "skView" it crashes.
var skView=view as SKView;
var skScene=gameScene();
skView.presentScene(skScene)
I have an UIView that i want to add a SKScene to. In the step were i declare "skView" it crashes.
var skView=view as SKView;
var skScene=gameScene();
skView.presentScene(skScene)
The
asoperator doesn't work that way. In order to treat a value of one typeasanother type, two things need to be true:You've got the first, but not the second. For example, if I give you something and all I say is that it's a
Car, you're welcome toaccelerate()it all you want (don't forget tobrake()too), but if you want toengageClutch()you'll need to treat itasaStickshiftCar. I may or may not have given you aStickshiftCar, though—if what you actually have is something else, you can't just say "treat this like a stickshift" to make it one.If you want to use an
SKView, you'll first need to get yourself one. If your view is set up in a storyboard, use IB to make the view controller's root view anSKView. Then, in code, you can accessself.view(which is just aUIViewfor all that property knows) and safely treat itasanSKView.