SKUButton
IntroductionSKUButton: Intended as a cross platform, unified way to design buttons for menus and input, instead of designing a completely different interface for Mac, iOS, and tvOS. Still needs a bit more effort when used on tvOS, but shouldn't be too hard. Note: anchorPoint (and potentially other) SKSpriteNode properties have no effect - it is only subclassed as a sprite to help with Xcode's scene creation tool and determine a minimum boundary. Also Note: when using action or notification button methods, the release of a button will only trigger the button release methods when the release is in the bounds of the button. However, using the delegate method, you will see the delegate called in both situations as well as a boolean passed that will tell you if the release is in bounds or not. WARNING: This class is not intended for direct usage: instead, use SKUPushButton, SKUToggleButton, or SKUSliderButton. While it's not what I would define as "risky", you will likely get better results by using the subclasses. You are also free to subclass. Use the other subclasses as a reference. GroupsButton actionsGroup members:
Button stateGroup members:
InitializationGroup members:Methods
buttonPressed:-(void)buttonPressed:(CGPoint)location; DiscussionCalls the actions for button down press. Location is in local space. buttonReleased:-(void)buttonReleased:(CGPoint)location; DiscussionCalls the actions for button release. Location is in local space. buttonStatesDefault-(void)buttonStatesDefault; DiscussionSets all states based off of the default state using the settings determined in [SKUButtonSpriteStatePropertiesPackage packageWithPropertiesForDefaultState:(SKUButtonSpriteStateProperties *)defaultState] Behaves similarly in subclasses, but also applies to the additional state packages included on those. buttonStatesNormalize-(void)buttonStatesNormalize; DiscussionSets all states based off of the default state. WARNING: baseSpritePropertiesDefault, baseSpritePropertiesPressed, baseSpritePropertiesHovered, and baseSpritePropertiesDisabled all point to the same pointer as a result. If you edit one state, they will all change. If you don't want them all to change with an edit, do SKUButton* button; // assuming this is properly set up [button buttonStatesNormalize]; button.baseSpritePropertiesPressed = button.baseSpritePropertiesPressed.copy;Behaves similarly in subclasses, but also applies to the additional state packages included on those. buttonWithImageNamed:+(SKUButton*)buttonWithImageNamed:(NSString*)name; DiscussionCreates and returns a button with a base sprite of the image named. buttonWithPropertiesPackage:DiscussionCreates and returns a button with a base sprite package. buttonWithTexture:+(SKUButton*)buttonWithTexture:(SKTexture*)texture; DiscussionCreates and returns a button with a base sprite of the texture. didInitialize-(void)didInitialize; DiscussionThis SHOULD be called after either raw init or initWithCoder. Meant to be overridden with post initialization purposes in custom subclasses. disableButton-(void)disableButton; DiscussionCall to explicitly disable button (meant to reverse the state of being enabled). Be sure to call super method if you override. enableButton-(void)enableButton; DiscussionCall to explicitly enable button (meant to reverse the state of being disabled). Be sure to call super method if you override. setBaseStatesWithPackage:-(void)setBaseStatesWithPackage:(SKUButtonSpriteStatePropertiesPackage*)package; DiscussionSets all base sprite states in one command. setDownAction:toPerformOnTarget:-(void)setDownAction:(SEL)selector toPerformOnTarget:(NSObject*)target; DiscussionIf button is set to call actions, set method and target to call on method when pressed down. Sets flag on self.buttonMethods to run actions. setUpAction:toPerformOnTarget:-(void)setUpAction:(SEL)selector toPerformOnTarget:(NSObject*)target; DiscussionIf button is set to call actions, set method and target to call on method when released. Sets flag on self.buttonMethods to run actions. Properties
baseSprite@property (nonatomic, readonly) SKSpriteNode* baseSprite; DiscussionReadonly access to the base sprite. While you can edit properties on the sprite itself, it is discouraged unless you really know what you're doing. baseSpritePropertiesDefault@property (nonatomic) SKUButtonSpriteStateProperties* baseSpritePropertiesDefault; DiscussionProperties to use on the base sprite in default state. baseSpritePropertiesDisabled@property (nonatomic) SKUButtonSpriteStateProperties* baseSpritePropertiesDisabled; DiscussionProperties to use on the base sprite in disabled state. baseSpritePropertiesHovered@property (nonatomic) SKUButtonSpriteStateProperties* baseSpritePropertiesHovered; DiscussionProperties to use on the base sprite in hovered state. baseSpritePropertiesPackage@property (nonatomic) SKUButtonSpriteStatePropertiesPackage* baseSpritePropertiesPackage; DiscussionReadonly access to a package for the base sprite properties baseSpritePropertiesPressed@property (nonatomic) SKUButtonSpriteStateProperties* baseSpritePropertiesPressed; DiscussionProperties to use on the base sprite in pressed state. buttonMethod@property (nonatomic) uint8_t buttonMethod; DiscussionUsed for enumeration of button ids To get the same result in Swift, be sure to use rawValue See Also buttonState@property (nonatomic, readonly) kSKUButtonStates buttonState; DiscussionCurrent state of the button To get the same result in Swift, be sure to use rawValue See Also buttonType@property (nonatomic, readonly) kSKUButtonTypes buttonType; DiscussionIdentifies button type. See Also delegate@property (nonatomic, weak) id <SKUButtonDelegate> delegate; DiscussionIf button is set to call delegate, this is the delegate used. See Also isEnabled@property (nonatomic, readonly) BOOL isEnabled; DiscussionReadonly: tells you if button is enabled or not isHovered@property (nonatomic, readonly) BOOL isHovered; DiscussionReturns whether the button is currently being hovered. notificationNameDown@property (nonatomic) NSString* notificationNameDown; DiscussionIf button is set to send notifications, this is the name of the notification. Can set the name here as well. notificationNameUp@property (nonatomic) NSString* notificationNameUp; DiscussionIf button is set to send notifications, this is the name of the notification. Can set the name here as well. sizeMinimumBoundary@property (nonatomic) CGSize sizeMinimumBoundary; DiscussionEstablishes the smallest possible area the button can take up (not accounting for properties with centerRect set that automatically expand). This is the same thing as setting the size property. It only exists to document clarity. whichButton@property (nonatomic) NSInteger whichButton; DiscussionUsed for enumeration of button ids - this is for you to set. Intended for use in switch statements. |