So I've made a quiz app in UIKit, with a question being displayed, four answers to pick from, etc. But since this project includes multiple mini-games, the rest of the project is written in SpriteKit. Is it worth it to rewrite the quiz app in SpriteKit, or is there some way I could include this UIKit mini-game into a SpriteKit project.
I've already tried to work with two classes like this:
public class GameScene: SKScene {
public var orientation: UIInterfaceOrientation!
let QuizScene = QuizScene()
override public func didMove(to view: SKView) {
fireQuizScene.setUpBushfireQuiz()
}
}
But it doesn't seem to work. Any help would be greatly appreciated. Thanks!
Stick with SpriteKit for games, and UIKit for the quiz.
Apple decided to develop SpriteKit because UIKit just does not have the proper tools to create a game.
Before Sprite Kit, people were on there own creating context windows out of open gl frame works, and it was a real hassle.
UIKit has nice features that keep your app responsive across all devices thanks to their constraints, which SpriteKit does not have.
Sprite Kit and UI kit integrate nicely, so do not fear with having your games in SpriteKit.
Just have your quiz in UIKit, and pop up an SKView for sprite kit when it is game time.
Related
Using Xcode 11.2 I can create a new project using the "Game" template. I can include for "Game Technology" SpriteKit and check "Integrate GameplayKit". If I run the code at this point on an iPhone 11 Pro iOS 13.2 simulator I see the "Hello, World!" label. If I go into the Library and add a Color Sprite at position (0,0) to the GameScene.sks file when I run I see the red Color Sprite. My problem comes when I add a Swift file with the content
import GameplayKit
class MovementComponent : GKComponent {
override func update(deltaTime seconds: TimeInterval) {
print(seconds)
}
}
and use the components editor in Xcode to add this component to the Color Sprite. When I run this I get a grey screen. When I check the GameViewController file I see with the debugger that scene.rootNode is nil. What's going wrong? I just want to see how to integrate a component with a Color Sprite using the components editor. Does this stuff work at all or is this just for WWDC demos?
Appears to be a bug in Xcode 11.2. Following the steps above the behavior appears correct for Xcode 10.3. Filled out Apple Feedback FB7427190. Thanks Knight0fDragon for helping identify where the problem was.
I guess my post today is a duplicate of this post.
SKScene not loaded when add GKComponent to GameScene.sks
It seems that the problem still exist in Xcode 11.3.1
If there is no component added in the scene editor to a SKSpriteNode I see that the scene is completely loaded as GameScene.sceneDidLoad is called.
If there is a GKComponent added in the scene editor. The GameScene is not loaded - GameScene.sceneDidLoad is never called.
Am I missing something obvious?
For reasons unknown, Xcode 10 keeps crashing on me when I go to assign a texture to a named sprite using the Scene Editor. After having to delete and recreate my .sks files a couple times, I decided to try and reproduce the issue using Xcode's game template. The steps I took to do this are as follows:
Open Xcode and select Create a new Xcode project.
Choose the Game template, name the project Test and save it somewhere, i.e. your desktop.
Drag any image asset into Assets.xcassets. I used this green square:
Open GameScene.sks and drag a Color Sprite onto the scene.
Name the sprite something descriptive like square_green.
Attempt to set the texture in this field:
Other similar questions on Stack Overflow:
Xcode is crashing in SpriteKit
XCode 9 Crashing while setting a Texture in SKScene in Spritekit
If I do not set a name for the color sprite prior to assigning a texture, everything works fine. However, if Xcode is forced to crash at least one time, I have to delete the .sks file completely just to get Xcode to open again.
For the time being I've decided to avoid the trouble all together and just assign the textures programmatically in the didMove(to:) of my SKScene class:
override func didMove(to view: SKView) {
let greenSquare = childNode(withName: "square_green") as! SKSpriteNode
greenSquare.texture = SKTexture(imageNamed: "square_green")
}
I ran into the same problem, and later I moved the images out of Assets.xcassets and the problem was solved. I guess the image can't be placed in Assets.xcassets.
I made a game for iOS using SpriteKit.
Now I wanna make also the version for watchOS.
I added a new target and then these files appear to me:
If I delete the sks file and then try to present a swift scene as I did for the iOS game the scene appears empty... So the only thing i could do is leave the scene.sks file as it was.
Can someone kindly explain to me how can to present a new scene.swift file in the interfaceController.swift without using the sks file?
Here is the InterfaceController.swift file that presents the sks scene, but I wanna present my own swift scene.
Best Regards.
exchange the GameScene(filenamed:) with `YourScene(size:).
Your scenes are a subclass of SKView which have their primary initializers... here is the link to the one I showed:
https://developer.apple.com/reference/spritekit/skscene/1520435-init
So (filenamed:) is one initializer (for .sks) and (size:) is another initializer, for not having .sks. These initializers are the exact same kind of initializers you use for all of your own classes.
This just isn't readily apparent, because when you make your own GameScene: SKScene you don't specify initializers (because they are inherited from SKScene that you just subclassed from)
the video below also covers most of the necessary things for SK on AW.. it's timestamped to explain more of what you're doing:
https://youtu.be/REv-w2rBsng?t=1173
the info in the above video is virtually nowhere else that I could find, so I highly recommend you watch it from begin to end.
NOTE:
(last I checked)
Your vanilla SKScenes won't work on the watch, because they lack certain functions (like touchesBegan) because you are no longer using an SKView to present your scene. So, you must use gesture recognizers..
Here explains how to get around that stuff:
TouchEvents in watchOS 3 SpriteKit?
I have an iOS app that dynamically draw shapes on UIView (through drawRect), and I am looking at the possibility to port that app (or a small part of that) to Apple Watch. Unfortunately, after read through relative posts I cannot find which class can handle the similar job in WatchKit.
So the question is:
If there is a similar class like UIView, in WatchKit, to draw lines cycles on Apple Watch?
What is the best (possible) way to implement a simple drawing function on Apple Watch, if there is no UIView like class. (Assume this is achievable)
Thanks in advance.
No, there is no class similar to UIView in WatchKit
You can generate images and transfer them to Watch App using WKInterfaceImage's func setImage(image: UIImage?)
If you already have drawing code for drawing in -drawRect:, it shouldn't be that difficult to modify it to support drawing to image
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)
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.