Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I mix UIKit and SpriteKit?

I am making a game in Swift. I have used both UIKit and SpriteKit, but never in the same app. I was wondering how to leverage the power of both of them (They are going to be a lot of menus). If you knew a tutorial I could use, or could tell me, I would be very appreciative. I also would like to know if there is a shortcut for this in xcode (e.g. storyboards)

like image 800
Jerfov2 Avatar asked Feb 14 '15 15:02

Jerfov2


People also ask

Can you use SpriteKit with SwiftUI?

Even though the default Game Xcode Template creates the project based on a UIKit application, you can create a SwiftUI app and put your SpriteKit game inside it without any hustle thanks to the SpriteView view!

What is SpriteKit and Scenekit?

Sprite Kit is meant to create 2D games. This would include games like Candy Crush or Angry Birds. Scene Kit is meant to create 3D games. This would be games that have various camera angles and is set in 3D (can't think of any notable examples).

What is a node in SpriteKit?

SpriteKit is a framework that helps you create animated 2D scenes and effects. Every scene in SpriteKit is made up of nodes. The scene object (SKScene) is the root node and any additional content in the scene are nodes (SKSpriteNote) built off of the root node.

What is SpriteKit in Swift?

SpriteKit is a general-purpose framework for drawing shapes, particles, text, images, and video in two dimensions. It leverages Metal to achieve high-performance rendering, while offering a simple programming interface to make it easy to create games and other graphics-intensive apps.


1 Answers

I would highly recommend you to stick with SpriteKit and to create menus etc with SKNodes. I know that it is really seductive to use UIKit in a game for buttons etc. but you've got many possibilities right in SpriteKit which replaces UIKit-elements.

For example you can use an SKLabelNode instead of an UILabel. Also you've got many more possibilities in SpriteKit to make your menu 'smooth' (For example with SKTransition or SKAction).

Also an example for a menubutton would be:

//Button
var playButton = SKSpriteNode(imageNamed: "yourImage.png")
playButton.position = CGPointMake(300, 300)

playButton.name = "playButton"

addChild(playButton)

Then in your touchesBegan method you can handle that button touch.

Also one very important point to only use SpriteKit is, that you can port a iOS game to OSX within a few hours.

like image 61
Christian Avatar answered Sep 21 '22 19:09

Christian