skscene

Overlay SKScene is not showing

大憨熊 提交于 2019-12-05 16:53:49
I'm trying to overlay an SKScene over a SCNScene. When I run my app on the simulator and an iPhone6+, the overlayScene(SKScene) is shown as intended, but when I tried running it on the iPhone5 (tried 2 different devices) the overlayScene does not appear. Does anyone have an idea why? Both device run on iOS 9.2.1. I have only tested the app on those two models. Here's my code inside the GameViewController.Swift //Configure the view sceneView = self.view as? SCNView //Configure the scene sceneView.scene = gameScene sceneView.playing = true sceneView.backgroundColor = UIColor.blackColor()

What is the method unarchiveFromFile in GameViewController for?

≡放荡痞女 提交于 2019-12-05 13:45:51
When I tried to add different scenes to my game in Swift, I encountered the method unarchiveFromFile. The problem with this method is that it only works with the GameScene class. If you call it from extension SKNode { class func unarchiveFromFile(file : NSString) -> SKNode? { if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") { var sceneData = NSData.dataWithContentsOfFile(path, options: .DataReadingMappedIfSafe, error: nil) var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData) archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene") let scene

Create Button in SpriteKit: Swift

大憨熊 提交于 2019-12-05 03:59:17
I want to create a button in SpriteKit or in an SKScene that sends the view to another view controller. I tried using the "performSegue with identifier ", however apparently an SKScene doesn't support this. How would I create a button that sends the view to another view with SpriteKit ? This is the code that I've tried using to perform this action. The line with "HomeButton.prepareForSegueWithIdentifier()" is just an example. It won't actually let me add the "prepareForSegue" part, it doesn't support it <--- What I mean by that is when I go to add it, it is unrecognized. class GameOverScene:

Swift 3 (SpriteKit): Reseting GameScene doesn't deallocate

与世无争的帅哥 提交于 2019-12-04 21:12:38
I have been trying to reset the GameScene by creating a new duplicate of the GameScene, which works. However, the problem is that the scene doesn't deallocate, which is definitely an issue since I profiled my app with Allocations and saw that the memory was 'clogging' and 'piling' up. This is my code for my GameViewController and my GameScene: import UIKit import SpriteKit import GameplayKit var screenSize = CGSize() class GameViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() if let view = self.view as! SKView? { // Load the SKScene from 'GameScene.sks' if

Simplest Way To Change Scene In Swift + Sprite Kit [closed]

萝らか妹 提交于 2019-12-04 11:48:55
I am just wondering what the simplest way to change scenes in Swift + Sprite Kit is? when changing between scenes, you're going to need to set up a transition, how the scene will change to the next and define which scene you want to transition to. For the transition, var transition:SKTransition = SKTransition.fadeWithDuration(1) The fadeWithDuration can be replaced with any SKTransition a list of which can be found in the documentation https://developer.apple.com/library/prerelease/ios/documentation/SpriteKit/Reference/SKTransition_Ref/index.html as for defining the scene, var scene:SKScene =

Delay when calling SKLabelNode?

人盡茶涼 提交于 2019-12-04 10:36:12
I am having a problem with a slight delay (lag) when transitioning from one SKScene to another. By commenting out various bit of code I have narrowed this down to SKLabelNode , my guess is thats its loading / caching the font when called which is resulting in a small delay/stutter when stating up the new SKScene . Has anyone else noticed this, its less obvious when your just using a single SKScene (like the default template) as the slowdown just gets lost in the usual startup delay. Does anyone know a way round this, is there a way to pre-load the font? I guess I could load the font on the

Presenting a scene in SpriteKit without discarding the previous?

﹥>﹥吖頭↗ 提交于 2019-12-04 09:34:40
My situation is that I have a GameMenuScene and after the user chooses a level, I want to present the LevelScene . But I do not want to have the previous GameMenuScene discarded because the LevelScene is actually a @property of GameMenuScene and whether or not the user completes the level is to be saved as a @property of LevelScene , which the GameMenuScene should be able to access after the user finishes or exits the level. If I simply use presentScene:transition , the GameMenuScene is discarded and the information cannot pass back. My question: Is there a way to stack or push the scenes on

Using SpriteKit inside SwiftUI

不羁岁月 提交于 2019-12-04 05:20:34
I am having an issue when creating a SpriteKit scene within SwiftUI . I created this project initially as a SwiftUI project. Here is the code I have so far: ContentView.swift: /// Where the UI content from SwiftUI originates from. struct ContentView : View { var body: some View { // Scene SceneView().edgesIgnoringSafeArea(.all) } } SceneView.swift: /// Creates an SKView to contain the GameScene. This conforms to UIViewRepresentable, and so can be used within SwiftUI. final class SceneView : SKView, UIViewRepresentable { // Conformance to UIViewRepresentable func makeUIView(context: Context) ->

How to add a swipe gesture to a node in spritekit

回眸只為那壹抹淺笑 提交于 2019-12-04 05:01:57
问题 I'm trying to add a swipe gesture to a node so that when a user swipes it, it goes off screen but I keep getting a SIGABRT error: `Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[fidget2.PlankScene swipedRight:]: unrecognized selector sent to instance 0x7ff4c3603e00'` I'm not sure why this error is popping up. I made sure the node is labeled correctly in the .sks file. Here is my code: import SpriteKit let plankName = "woodPlank" class PlankScene: SKScene {

dismiss SKScene go back to UIKit Menu

佐手、 提交于 2019-12-04 03:38:39
问题 Once my SpriteKit game has ended, I would like to go back to my UIKit MenuViewController . From what I've learned so far, using protocol/delegate is the best(?) option, but I haven't been able to get that to work. I know that the protocol would probably go above the class declaration for GameViewController , and look something like: protocol GameViewControllerDelegate { var gameOver: Bool? } But I need help accessing that from GameScene AND getting it to dismiss GameViewController . Below are