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)
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!
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).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With