Note:
There are several questions (or resources) already out there in relation to this:
Present an UIAlertController with a SpriteKit scene (Objective-C)
Displaying a UIAlertController in GameScene (SpriteKit/Swift)
So I am sorry for adding a similar question. However, I have attempted to implement those solutions without success.
To make this question a bit more concrete than the aforementioned question, let's use the M.W.E. (Stack Overflow SKSpriteKit) presented in two other Swift related questions:
- Swift: SKSpriteKit, using Storyboards, UIViewController and UIButton to set in game parameters?
- Swift: returning to Main Menu after condition is met in GameScene using StoryBoards and UIViewControllers?
Context:
In the M.W.E.
there is one main UIViewController
, GameViewController
that calls forth the main menu scene, which is an SKView
. The various custom SKView
s link cyclicly:
menu -> difficulty -> game -> score -> menu -> etc
I mention this, because in most of the above questions, one must add the UIAlertController
to the main UIViewController
. I just want to make sure that only the GameScene
can present the UIAlertController
and none of the other scenes.
Question:
How can I implement a UIAlertController
callable from only one of the SKView
s? Some of the previous answers, have only the main GameViewController
and GameScene
, and then give the GameScene
(a constant in the GameViewController
) a reference to the GameViewController
. Since in this code, the GameScene
isn't accessed until much later, how can this be achieved (ideally without propagating a reference to the GameViewController
through the various SKView
s.
Please use the M.W.E. when answering this question.
Goal:
In another related question,
Swift3: UISwipeGestureRecognizer in only one of putatively many SKViews, it posed as to how to implement a UIGestureRecognizer
for one SKView
. Ideally, the UIAlertController
would be presented following that action - as sort of an in game menu.