I'm writing some games for Mac OS (using AppKit with storyboards and without core data) and my project is quite big, so rewriting it using SpriteKit will be very difficult and long process. So, is there any way to add a game written on SpriteKit to this project?
This is exactly what the SpriteKit Game template you can start a new app with in Xcode is. There's nothing magic about it — it's an AppKit app, containing an SKView that displays an SKScene.
Take a look at a new project created with that template to see how it works. Create an SKView in code or in IB, make an outlet to it, and from your app's controller code (say, in the app delegate or a window controller), create a scene and pass that to the view's presentScene method.
Related
I have made a tabbed application using the storyboard, and each tab has its own view controller. Currently, each tab does nothing but display an image, but I need to add some existing code to each view controller that some partners have coded up. I'm very new to xcode and swift, and am wondering how to do this. These were coded without using the storyboard, but mine was exclusively using the story board. Would I just need to copy the viewcontroller.swift onto each one that I have in my skeleton UI?
Thank you for any help.
Would I just need to copy the viewcontroller.swift onto each one that I have in my skeleton UI?
Not just copy it. There are two stages. To illustrate, let’s say that we’re going to have the code for one of your tabs in a view controller called MyViewController1. Then:
You need to declare class MyViewController1. This is usually done in a file MyViewController1.swift (though no law requires that).
You need to tell the storyboard that this view controller is a MyViewController1 (and not merely a plain vanilla UIViewController). You do that in the scene’s view controller’s Identity inspector.
I am trying to add a nscollectionview to my OSX project but this will causes Xcode to force-close:
Every time when I am dragging the collectionview into the storyboard Xcode will be force close.
I do not know either I am the only one having this problem or everyone else has work around solution.
This seems to happen when targeting operating system verisons that don't support macOS 10.11+ UIKit-style NSCollectionViews.
I was able to get an "old-style" collection view into a storyboard by dragging one into a xib file, then opening it as XML text and copy-pasting the <collectionView> into the <subviews> of a parent view in the storyboard file.
(Swift) I have a problem with my app, I'm working on. It features a SpriteKit Scene and some transitions to different scenes. However, from the main menu of the app, I've created a segue to a new viewController via Story Board.
My problem is, when I - in my sprite kit scenes, browse back to the main menu to trigger the Story Board scene my app crashes.
I can only use the Story Board segue if restart my App and triggers it from the main menu as the first thing.
Also, when I get back to my Sprite Kit Scene from the new viewController, I cannot use any of the nodes (as buttons) to make transitions to other sprite kit scenes.
I've tried to illustrate it here:
Code for calling the segue:
func goto_achievements() {
self.viewController?.performSegueWithIdentifier("achievements", sender: self)
}
Any help appreciated!
One of my main reason for using Xcode instead of other applications for making iOS apps was the storyboard interface builder. I was unhappy when I found out that you are not meant to use storyboards with spriteKit. I find it hard to design a nice interface for a game's menu without a good visual builder. Is there a way to start a spriteKit application using storyboards, then with a click of a "start game" button, switch to spriteKit scenes, then when you lose the game, in the code switch back to storyboards(using swift)? Please help and thanks.
-Callum-
A SpriteKit Scene is presented on an instance of a SKView, which is a subclassed UIView.
For an iOS game made using SpriteKit, one needs to have at least one viewController set up, either programatically in the App delegate or in a storyboard, on which the SKScene can be displayed. It is on the main view of this VC that a SKScene will be presented in.
So if you are using a storyboard, the iOS game will have to instantiate the root viewController from it. You can easily design your UI on the viewController, and present the game from the code on the press of a button, either in the same viewController or a new one. All this will be evident once you read a beginner tutorial for SpriteKit using Swift like this.
Let's say your root viewController has your main menu (on another view called menuView), with a play button on it. Now presenting a game on the press of a button would look something like this:
class MyViewController: UIViewController {
#IBOutlet wear var menuView: UIView?
#IBOutlet weak var playButton: UIButton?
#IBAction func likedThis(sender: UIButton) {
//Hide the menu view
menuView.hidden = true
//instantiate and present the scene on the main view
let scene = MyScene(size: view.bounds.size)
let skView = self.view as SKView
skView.presentScene(scene)
}
}
As for going back to the main menu from the scene, have a look at this answer.
I am developing a puzzle game for the iPhone using core graphics implementing drawrect in a single UIView.
I would like to add a menu which is opened from a UIButton event handler.
I am not sure if I should do this via code e.g. have a menuopen flag and adjust the drawing routines and tap event handlers (manual implementation) or to go the UINavigationController route and have a completely separate view which would be activated i assume in the UINavigationController from the button event.
Currently my music and sound stuff is in a class attached to the "main" UIView in my game and initialised via ViewDidLoad.
Any advice would be greatly appreciated.
You should definitely put your menu code in a different view object. Don't just redraw the existing view in menu mode. That will make your code needlessly complicated.
You don't have to use UINavigationController to swap out one view for another, however. You write code yourself to remove the game view (removeFromSuperview) and add the menu view (addSubview:) to the application's window, using transition animations if you want.
You could also use UIViewController's presentModalViewController: method to push your menu view on top of the game view.
It's hard to say exactly what you need to do without knowing more about your code, but you should absolutely definitely keep different things as different classes, instead of making one class that acts as many things depending on a mode flag.