Zablah
Zablah

Reputation: 332

How can I add a UIview to a SpriteKit project?

I am working on a game with Sprite kit (swift) and I need a menu with buttons, stats, store etc.

I know I can make it with a SKScene but I want to edit it in the MainStoryBoard not only with code like in SKScene. If I create a new UIViewController file then just segue a button from that view to the SKScene will that be enough? Is it acceptable in terms of efficiency and memory management?

Upvotes: 0

Views: 792

Answers (2)

DanielEdrisian
DanielEdrisian

Reputation: 726

If you have a view controller in your storyboard (which you probably have if you go with apple's template), add a swift file like you do for any other app and connect it to your view controller.

Add any ui elements you want and add any actions and outlets. Just make sure your SKScene is being shown IN your view controller. In most cases that is precoded.

SKScene can also be implemented in a UIView, so you can also drag a UIView in a view controller and set it as an SKScene file.

Hope it helps :)

Upvotes: 0

jbcd13
jbcd13

Reputation: 143

I think that will work fine for you, but it might be harder to work from a new UIViewController file than from SKScene. How effective creating the new UIViewController file versus creating the SKScene in code depends on how comfortable you feel in swift, so its hard to tell which you would prefer. I do not see any problems with memory management, but it could be less efficient than an SKScene because an SKScene was arguably designed for what you are trying to do. In summary, I believe it will be fine for you to use a new UIViewController, but an SKScene is likely the better route.

Upvotes: 1

Related Questions