SKUButton

Superclass:
SKSpriteNode
Declared In:
See Also:

Introduction

SKUButton: 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.



Groups

Button actions

Group members:

 

Button state

Group members:

 

Initialization

Group members:


Methods

-buttonPressed:
-buttonReleased:
-buttonStatesDefault
-buttonStatesNormalize
+buttonWithImageNamed:
+buttonWithPropertiesPackage:
+buttonWithTexture:
-didInitialize
-disableButton
-enableButton
-setBaseStatesWithPackage:
-setDownAction:toPerformOnTarget:
-setUpAction:toPerformOnTarget:

buttonPressed:


-(void)buttonPressed:(CGPoint)location; 
Discussion

Calls the actions for button down press. Location is in local space.


buttonReleased:


-(void)buttonReleased:(CGPoint)location; 
Discussion

Calls the actions for button release. Location is in local space.


buttonStatesDefault


-(void)buttonStatesDefault; 
Discussion

Sets 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; 
Discussion

Sets 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; 
Discussion

Creates and returns a button with a base sprite of the image named.


buttonWithPropertiesPackage:


Discussion

Creates and returns a button with a base sprite package.


buttonWithTexture:


+(SKUButton*)buttonWithTexture:(SKTexture*)texture; 
Discussion

Creates and returns a button with a base sprite of the texture.


didInitialize


-(void)didInitialize; 
Discussion

This SHOULD be called after either raw init or initWithCoder. Meant to be overridden with post initialization purposes in custom subclasses.


disableButton


-(void)disableButton; 
Discussion

Call to explicitly disable button (meant to reverse the state of being enabled). Be sure to call super method if you override.


enableButton


-(void)enableButton; 
Discussion

Call to explicitly enable button (meant to reverse the state of being disabled). Be sure to call super method if you override.


setBaseStatesWithPackage:


Discussion

Sets all base sprite states in one command.


setDownAction:toPerformOnTarget:


-(void)setDownAction:(SEL)selector toPerformOnTarget:(NSObject*)target; 
Discussion

If 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; 
Discussion

If 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
baseSpritePropertiesDefault
baseSpritePropertiesDisabled
baseSpritePropertiesHovered
baseSpritePropertiesPackage
baseSpritePropertiesPressed
buttonMethod
buttonState
buttonType
delegate
isEnabled
isHovered
notificationNameDown
notificationNameUp
sizeMinimumBoundary
whichButton

baseSprite


@property (nonatomic,
    readonly) SKSpriteNode* baseSprite; 
Discussion

Readonly 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; 
Discussion

Properties to use on the base sprite in default state.


baseSpritePropertiesDisabled


@property (nonatomic) SKUButtonSpriteStateProperties* baseSpritePropertiesDisabled; 
Discussion

Properties to use on the base sprite in disabled state.


baseSpritePropertiesHovered


@property (nonatomic) SKUButtonSpriteStateProperties* baseSpritePropertiesHovered; 
Discussion

Properties to use on the base sprite in hovered state.


baseSpritePropertiesPackage


@property (nonatomic) SKUButtonSpriteStatePropertiesPackage* baseSpritePropertiesPackage; 
Discussion

Readonly access to a package for the base sprite properties


baseSpritePropertiesPressed


@property (nonatomic) SKUButtonSpriteStateProperties* baseSpritePropertiesPressed; 
Discussion

Properties to use on the base sprite in pressed state.


buttonMethod


@property (nonatomic) uint8_t buttonMethod; 
Discussion

Used 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; 
Discussion

Current state of the button

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

See Also


buttonType


@property (nonatomic,
    readonly) kSKUButtonTypes buttonType; 
Discussion

Identifies button type.

See Also


delegate


@property (nonatomic,
    weak) id <SKUButtonDelegate> delegate; 
Discussion

If button is set to call delegate, this is the delegate used.

See Also


isEnabled


@property (nonatomic,
    readonly) BOOL isEnabled; 
Discussion

Readonly: tells you if button is enabled or not


isHovered


@property (nonatomic,
    readonly) BOOL isHovered; 
Discussion

Returns whether the button is currently being hovered.


notificationNameDown


@property (nonatomic) NSString* notificationNameDown; 
Discussion

If 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; 
Discussion

If 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; 
Discussion

Establishes 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; 
Discussion

Used for enumeration of button ids - this is for you to set. Intended for use in switch statements.