SKUtilities2

Superclass:
NSObject
Declared In:

Introduction

This is a singleton class that carries a lot of information allowing for access anywhere within your app. It'll track the current time, intervals between frames, handle logging, store objects, and manage navigation and other built in utilties with this library.



Groups

Internal - best not to touch

Group members:

 

Singleton

Group members:

 

Navigational

Group members:

 

Time

Group members:


Methods

-gestureTapDown
-gestureTapUp
-handleSubNodeMovement:withCurrentFocus:inSet:inScene:
-idleTimerEnable:
-setNavFocus:
+sharedUtilities
-updateCurrentTime:

gestureTapDown


-(void)gestureTapDown; 
Discussion

Used internally to communicate logic for button presses.

Platforms:

tvOS


gestureTapUp


-(void)gestureTapUp; 
Discussion

Used internally to communicate logic for button presses.

Platforms:

tvOS


handleSubNodeMovement:withCurrentFocus:inSet:inScene:


-(SKNode*)handleSubNodeMovement:(CGPoint)location 
        withCurrentFocus:(SKNode*)currentFocusedNode inSet:(NSSet*)navNodeSet 
        inScene:(SKScene*)scene; 
Discussion

Used internally. Best not to touch.

Gets called when movement exceeds the navThresholdDistance. Logic determines which primary direction the movement was in and decides what node is closest in that direction.

Platforms:

tvOS


idleTimerEnable:


-(void)idleTimerEnable:(BOOL)enableIdleTimer; 
Parameters
enableIdleTimer

boolean determining whether idle time is enabled or not.

Discussion

Enables or disables the sleeping of the display on iOS and tvOS platforms. Off by default. Harmless on other platforms.

Platforms:

tvOS

iOS


setNavFocus:


-(void)setNavFocus:(SKNode *)navFocus; 
Parameters
navFocus

SKNode to set as the navFocus.

 
 SKUPushButton* buttonExample; // assuming this is created properly
 [self addNodeToNavNodesSKU:buttonExample];
 
 
Discussion

Call this method to update the current navFocus node. Typically used on scenes when initially presented.


sharedUtilities


+(SKUtilities2*) sharedUtilities; 
Discussion

Singleton object. Called via

 
 SKUSharedUtilities
 
 

Allows for storing objects in the userData NSMutableDictionary, carrying time information, managing tvOS navigation logic, and more.


updateCurrentTime:


-(void)updateCurrentTime:(CFTimeInterval)timeUpdate; 
Discussion

Call this method in your scene's update method to share the time with other objects throughout the game.

 
 -(void)update:(CFTimeInterval)currentTime {
        [SKUSharedUtilities updateCurrentTIme:currentTime];
}
 
 

Properties

currentTime
deltaFrameTime
deltaFrameTimeUncapped
deltaMaxTime
gcController
macButtonFlags
navFocus
navMode
navThresholdDistance
touchTracker
userData
verbosityLevel

currentTime


@property (nonatomic,
    readonly) CFTimeInterval currentTime; 
Discussion

Current time passed in from scene update method, but must be set up properly. This allows you to get the currentTime into other objects or methods without directly calling them from the update method.


deltaFrameTime


@property (nonatomic,
    readonly) CFTimeInterval deltaFrameTime; 
Discussion

Amount of time passed since last frame. This value is capped by deltaMaxTime.


deltaFrameTimeUncapped


@property (nonatomic,
    readonly) CFTimeInterval deltaFrameTimeUncapped; 
Discussion

Amount of time passed since last frame. This value is NOT capped by deltaMaxTime. Vulnerable to lag spikes if used.


deltaMaxTime


@property (nonatomic) CGFloat deltaMaxTime; 
Discussion

Defaults to 1.0f.


gcController


@property (nonatomic,
    strong) SKUGCControllerController* gcController; 
Discussion

Gives you access to controls from gamepad inputs. Setup is relatively simple - Change your SKScene superclass to SKUScene, modify your update method to call its super method, and be sure to call setNavFocus on the SKUSharedUtilities singleton, call SKUScene's didMoveToView super method, or manually set SKUSharedUtilities.gcController.view to the current view. This achieves several things: SKUScene has built in methods for overriding for each input button on controllers that get called when buttons are pressed as well as automatically updates [SKUSharedUtilities updateCurrentTime], and enables controllers for navigation within the game.

To fully enable navigation on tvOS requires a couple additional steps - Change your ViewController superclass to SKUViewController, making sure SKUSharedUtilities.navFocus is on the right node and making sure that SKUSharedUtilities.navMode is set. Once that is set, SKUViewController listens for notifications with the string constant kSKURemoteInteractionOn or kSKURemoteInteractionOff in the name. When kSKURemoteInteractionOn is set, the A button on the controller will double as the Siri Remote select button and the B and Pause buttons will double as the menu button. SKUSharedUtilities.navMode operates independently of this setting - you will likely want to use SKUSharedUtilities.navMode within your game, but when you're on the top menu of the game, likely activate kSKURemoteInteractionOn so your game can exit to the tvOS menu. Once descended into game menus, kSKURemoteInteractionOff will likely be activated so the player won't accidentally leave the game when they only meant to go up a menu within the game.


macButtonFlags


@property (nonatomic) kSKUMouseButtonFlags macButtonFlags; 
Discussion

Flags to determine what sort of mouse button is passed onto nodes. By default, it only passes left mouse button events, but adding other kSKUMouseButtonFlags flags allows to respond to other mouse buttons.

To get the same result in Swift, be sure to use rawValue

Platforms:

OSX

See Also


navFocus


@property (nonatomic,
    weak) SKNode* navFocus; 
Discussion

Allows for access to and setting the current navFocus node.

Set via

 
 [SKUSharedUtilities setNavFocus:self]; //called from a node
 
 

When navMode is on, whatever node is set here is the node that dictates what nav nodes are used. Typically this will be set to the current scene that you will then call

 
 SKUPushButton* buttonExample; // assuming this is created properly
 [self addNodeToNavNodesSKU:buttonExample];
 
 

Note that only SKUButton nodes (and subclasses) are set to automatically distinguish focus states when focused or removed from focus. For your own nodes, you can use whatever current navFocus is set when it calls

 
 -(void)currentFocusedNodeUpdatedSKU:(SKNode *)node {
        //do logic here to update visuals
 }
 
 

See Also


navMode


@property (nonatomic) kSKUNavModes navMode; 
Discussion

Allows you to set the current kSKUNavModes type.

See Also


navThresholdDistance


@property (nonatomic) CGFloat navThresholdDistance; 
Discussion

Change this value to change how sensitive the Siri remote or controller is to movement. The concept is that from one navigation movement to another, this is the distance your touch must travel before signalling another navigational focus change. Higher values are less sensitive.


touchTracker


@property (nonatomic,
    strong) NSMutableSet* touchTracker; 
Discussion

Used internally to track current touches. Best not to touch.

Platforms:

tvOS


userData


@property (nonatomic,
    strong) NSMutableDictionary* userData; 
Discussion

This mutable dictionary is similar in concept to the item of the same name on all SKNodes that Apple does, but on the singleton allows you to store objects for access game wide, not just on one node. It remains uninitialized until you initialize it.


verbosityLevel


@property (nonatomic) NSInteger verbosityLevel; 
Discussion

Used to determine if SKULogs print to the console. A value of 100 or more will automatically print notifications of SKScene deallocation. A value of 150 will print notifications of SKNode deallocation.

See Also