SKUtilities2
IntroductionThis 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. GroupsInternal - best not to touchGroup members:
SingletonGroup members:
NavigationalGroup members:
TimeGroup members:Methods
gestureTapDown-(void)gestureTapDown; DiscussionUsed internally to communicate logic for button presses. Platforms:
gestureTapUp-(void)gestureTapUp; DiscussionUsed internally to communicate logic for button presses. Platforms:
handleSubNodeMovement:withCurrentFocus:inSet:inScene:-(SKNode*)handleSubNodeMovement:(CGPoint)location withCurrentFocus:(SKNode*)currentFocusedNode inSet:(NSSet*)navNodeSet inScene:(SKScene*)scene; DiscussionUsed 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:
idleTimerEnable:-(void)idleTimerEnable:(BOOL)enableIdleTimer; ParametersDiscussionEnables or disables the sleeping of the display on iOS and tvOS platforms. Off by default. Harmless on other platforms. Platforms:
setNavFocus:-(void)setNavFocus:(SKNode *)navFocus; ParametersDiscussionCall this method to update the current navFocus node. Typically used on scenes when initially presented. sharedUtilities+(SKUtilities2*) sharedUtilities; DiscussionSingleton 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; DiscussionCall 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@property (nonatomic, readonly) CFTimeInterval currentTime; DiscussionCurrent 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; DiscussionAmount of time passed since last frame. This value is capped by deltaMaxTime. deltaFrameTimeUncapped@property (nonatomic, readonly) CFTimeInterval deltaFrameTimeUncapped; DiscussionAmount of time passed since last frame. This value is NOT capped by deltaMaxTime. Vulnerable to lag spikes if used. deltaMaxTime@property (nonatomic) CGFloat deltaMaxTime; DiscussionDefaults to 1.0f. gcController@property (nonatomic, strong) SKUGCControllerController* gcController; DiscussionGives 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; DiscussionFlags 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:
See Also navFocus@property (nonatomic, weak) SKNode* navFocus; DiscussionAllows 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; DiscussionAllows you to set the current kSKUNavModes type. See Also navThresholdDistance@property (nonatomic) CGFloat navThresholdDistance; DiscussionChange 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; DiscussionUsed internally to track current touches. Best not to touch. Platforms:
userData@property (nonatomic, strong) NSMutableDictionary* userData; DiscussionThis 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; DiscussionUsed 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 |