Focus on SKNode in SKView with SpriteKit Scenes

Hi guys,


I'm working on porting one of my existing apps to both tvOS and SpriteKit, both of which are new to me.

Given these are already new, I'm sticking to what I know and doing the majority in Obj-C and branching into Swift when/if/where I feel comfortable.


The problem I'm having is translating how the focus works for a SpriteKit Scene, and adding focus to a SKNode.

Anyone have any tips on how this is meant to work?


Am I meant to catch and throw from my main UIViewController?

I'm spiking out with a simple Game using SpriteKit boilerplate, but the UIFocusEnvironment documentation isn't jelling with me.t

Okay, so this will form my findings and log of trials.


I found (what seems like additional information) a reference to a helper/convenience method called _whyIsThisViewNotFocusable , which I called in the boilerplate GameViewController.., which told me two things:


ISSUE: This view is not contained in a window view hierarchy.
ISSUE: This view returns NO from -canBecomeFocused.


So I created a new subclass of SKView, and implemented the canBecomeFocused method to return YES.


After this, I found that I actually finally got a callback to the UIFocusEnvironment didUpdateFocusInContext


I then reduced my error(s) to one:

ISSUE: This view is not contained in a window view hierarchy

The focus system only supports UIViews. While you can subclass SKView to make it focusable, this will only focus the SKView itself (and you will be responsible for defining the focused appearance of SKView). SKView is just a container for SKNodes, which are not UIViews, so they will not be focusable. If you wish to focus on SKNodes, you will need to define your own system for managing that separate from the UIView system.


If there are enhancements to SpriteKit and the focus system that you'd like to see in the future, please file a bug report at https://bugreport.apple.com/

Thanks matt.. I was fearing this, so I've started defining my own solution for detecting input from indirect controllers to drive the focus of my Nodes..

Focus on SKNode in SKView with SpriteKit Scenes
 
 
Q