Menu Screens (e.g. Inventory Screen) on a SceneKit game - ios

I just started to learn SceneKit/SpriteKit to develop games, and while I understood the game part (the SCNScene, in my case), I’m not so sure about the menu/hud part.
What I want to do: create an Inventory Screen to show the items the player has in his bag. This screen will appear when the user taps the bag Icon in the HUD. Furthermore, the Inventory Screen must have a UICollectionView-like list to show each item.
Game Hud:
Inventory Screen:
My question is: should I mix SpriteKit with UIKit to try to accomplish this? Or use just one of them? Should everything be done just with SKScenes that are shown on top of each other (by adding to the OverlaySKScene)?
Currently, I’m presenting the HUD as a SKScene (OverlaySKScene). When the user taps the bag icon, I’m loading a new SKScene (with a bunch of SKSpriteNodes, SKShapeNodes etc) and putting it as the current OverlaySKScene. Now, I’m trying to do the CollectionView part, but don’t know if I should try to implement everything from scratch with SpriteKit or if it’s possible to reuse UICollectionView, with my SKScene as a delegate.
I'm not sure if the way I'm doing is the right way, either.
Any help would be appreciated.
Thanks in advance.

Related

How to build a PagerView in WatchOS

How can I build or get (library) a PagerView in WatchOS. I can't find a way to do it without SwiftUI. I have a library for UIKit (https://github.com/WenchaoD/FSPagerView) but i cant use it for watchOS
Use SpriteKit for custom ui on watchOS
If you can't use SwiftUI, WatchOS only has SpriteKit and SceneKit.
Your app isn't a game, but there's no difference to the computer, only to the user. A game is just a fun app.
You need to have a WKInterfaceController that hosts a WKInterfaceSKScene view and the WKInterfaceSKScene presents an SKScene
For a pager type view of images that you can swipe between, then you might have a scene with some SKSpriteNodes, for example 3, with one on screen, one to the left, one to the right, and move them around and change their images as user drags about. Or whatever you want, maybe a SKTileMapNode or so.
For dragging, maybe a WKPanGestureRecognizer on the WKInterfaceController - you need to ensure you're not in a paged based interface, only fullscreen or navigation based would work for that. You also want to allow the crown to be used, so implement WKCrownDelegate

Architecture of a SceneKit game, multiple view controllers for menu screens?

I'm working on a SceneKit game using Swift, and I'm thinking about the best way to organize the various screens/ states surrounding the actual main game scene. I have a simple prototype which consists of three states:
Splash Screen (choose game type) ->
Game ->
Game over screen (choose to play again or return to splash)
In the prototype I opted to go for UIKit to do the UI elements, rather than a SpriteKit overlay. Although it's just buttons at the moment, which would be easy enough to do in SpriteKit, I might in future want to add sliders (eg an options screen to set control sensitivity etc), text entry etc, and then you end up recreating great chunks of uikit.
So at present, each of the 3 scenes described above has its own UIViewController. The Splash and Game ViewControllers have their own SCNViews and SCNScenes, and the GameOver is a modal that displays over the main Game scene.
This structure isn't really ideal, as it means that the main game SCNScene gets reloaded whenever the viewDidLoad of the GameViewController fires. The main SCNScene is quite detailed so takes a few seconds to load, and with repeated cycles this seems to create memory issues. After 2 cycles of Splash -> Game -> GameOver I get a memory warning, and after the third cycle Xcode loses the connection to the iPhone (which seems, in my experience, to be caused by memory issues).
I would like to have a main GameViewController that loads the most frequently reused assets once, but still be able to segue between the various menu screens.
So what are the options here?
I thought perhaps I could have a main GameViewController which controls the loading and unloading of SceneKit assets and has the sole SCNView. Its viewDidLoad method would only be fired once, when the app first starts. Then, each of the other views would have a very minimal UIViewController, which would be presented as modals over the main GameViewController, with "OverCurrentContext" selected.
I wanted to ask whether this pattern sounds feasible, and how others organise their SceneKit games. I'm still quite new to native iOS development, so it could be that I'm missing some basic game design pattern.
My Experience with the use of only one GameViewController (my current work for MAC OS X: i started a a 'small' 3D game with a MainMenu/start screen, a Hud and 2 or 3 complete different 3D Scenes - this shall be ported then to IOS, too):
In the last week i tried what you asked for, to use only one GameViewController for "all" that stuff - for me it seemed to be the easy and "good" way to do it - but even after lot of hours with all my tricks I've learned the last years i was not able to reload load another (or change) 3D scene (or even not another sprite kit scene hud) after a scenekit scene is loaded in a single ViewController.
Maybe there is difference between MAC OS X and IOS but i even tried this in an iOS version and it has the same behavior.
What i was able to do: You can modify a loaded 3D scene or change data in the sprite kit hud etc., so you are able to use one 3d scene to add or show the things up when they are needed but as far as my tests here showed, you will need one ViewController to show up a complete new different 3d scene or 2d/3d Menus etc. I will post my further experiences as soon as I'm a step further. i hope this helps a little.

iOS Cloudy UIViewController Background

I am trying to create my first iOS app using Swift and Xcode 7.2. I am using SpriteKit to make Tetris. After the user loses, the view switches from a UIViewController with a SKScene inside it, in which the game runs, to a UIViewController that is a death screen saying the user's score and their high score. I was wondering if there is a way to have a background on the death screen have a translucent background so that the user sees the game they just played in the background. Any help would be great. Thanks:)
In the UIViewController of your game, you can add a SubView with a blur effect: http://www.ioscreator.com/tutorials/add-blur-effect-ios8-swift
Your view need to have a smaller zPosition than your "game over button" for exemple. So when the game is over, you add the "blurred view" and on it you add your other things like the score label. When the user restart the game you just need to remove the view and restart your game.

App crashes transitioning scenes swift sprite kit

I am building an app that has a main scene and a restart scene. The main game scene uses sprite kit physics to have an object controlled by the user float across the screen. When it rashes into an obstacle the app transitions to the end scene using:
self.presentScene.restartscene.
This works just fine. then the restart scene has a restart button. when this is clicked the app transitions back to the game scene using:
self.presentscene.gamescene
i know this presents the original scene because i did an ns log to make sure. The problem is when this original scene is presented again the scene changes colors multiple times alternates very quickly between one and two nodes on the screen and then crashes. I have no idea the cause. i have had this problem before and i know other people have. no one has given me a definite answer. i hope one of you guys will. Thank you. help needed badly!!!!!!!
Try to navigate between scenes this way:
let nextScene = GameScene(fileNamed: "SceneNameHere")!
scene?.view?.presentScene(nextScene)
Also please check your code on startup in the gamescene.
May be you are using some global flags to store value for win/fail/restart conditions and your scenes simply open together one by one (it is hard to say without checking actual code).
You need to remove the original seen from view after transitioning away from it. Use this code:
myView.removeFromParentViewController()
Hope this helps :)

Presenting a new viewController doesn't seem to unload the previous

The game I'm developing consists of a Main Menu, and Game viewController separately.
However when moving from the game screen to the menu screen, it seems as if the class files from the previous viewController are still in effect?
For example, players start the game by tapping anywhere on the screen whilst in the game viewController, which causes a new bar to be "launched", which in turn plays a small tone which varies depending on the direction. However when returning to the main menu after the game is over (achieved by pressing a button to present the menu viewController), tapping anywhere on the menu screen seems to start the game again from the game viewController?
By this, I mean the bar launch sound is played, despite there being no code available in the main menu viewController to play said sound, pressing play on the menu will take you to the game screen, where the game has been reset, until tapping again, where the sound plays implying a new bar is launched, despite all images being invisible.
I made sure that, when leaving any view, I wipe all subviews from the view, so that whenever the screen is loaded there's nothing being covered up. I also tried dismissing the previous view controller, however nothing seems to take effect. So, I can't tell for certain whether the views are being removed or what... It's simply mind breaking to me.
Unfortunately my descriptions most likely aren't doing myself any justice, so hopefully this video demonstration will help out. Note that at the beginning, I am tapping the screen to show that no sound is played, however of course that won't be visible.
Edit: You'll notice that when returning to the menu, tapping the screen seems to mess up the moving bar in the background, despite the gameBarMovement timer being invalidated upon moving from the game to the menu. The fact that they're using separate class files also should mean the bars shouldn't be effected? Knowing me, I've missed something fairly obvious.
This is how the UIViewController life-cycle works as far as I know. UIViewcontrollers aren't unloaded until the app starts running out of memory. What you probably need is some way, in your game VC, to stop the game loop from running and resume it once a new game is started.

Resources