Inherits from NSObject
Conforms to NSCoding
NSCopying
Declared in KKBehavior.h

Overview

Behaviors add custom logic to a node. Behaviors differ from actions in several ways:

  • they are useful for any logic code that is hard or impossible to implement with (custom) actions, such as event processing
  • they usually run indefinitely and can be paused by pausing the controller
  • they may have a state (ivars)
  • they may have a public interface (properties, methods)
  • they can not be reversed

Properties

controller

The behavior’s node controller.

@property (atomic, weak) KKNodeController *controller

Return Value

The behavior’s node controller.

Declared In

KKBehavior.h

enabled

Whether the behavior is enabled. Disabled behaviors don’t receive update messages.

@property (atomic) BOOL enabled

Return Value

Whether the behavior is enabled. Disabled behaviors don’t receive update messages.

Declared In

KKBehavior.h

key

The behavior’s uniquely identifying key.

@property (atomic, copy) NSString *key

Return Value

The behavior’s uniquely identifying key.

Declared In

KKBehavior.h

name

The behavior’s name.

@property (atomic, copy) NSString *name

Return Value

The behavior’s name.

Declared In

KKBehavior.h

node

The behavior’s owning node.

@property (atomic, weak) SKNode *node

Return Value

The behavior’s owning node.

Declared In

KKBehavior.h

Class Methods

behavior

Creates a new instance.

+ (id)behavior

Return Value

The new instance.

Declared In

KKBehavior.h

Instance Methods

didChangeEnabledState

Sent when the enabled state of the behavior was changed.

- (void)didChangeEnabledState

Declared In

KKBehavior.h

didInitialize

Sent when the behavior is first created.

- (void)didInitialize

Declared In

KKBehavior.h

didJoinController

Sent when the behavior was added to a node.

- (void)didJoinController

Declared In

KKBehavior.h

didLeaveController

Sent when the behavior was removed from a node.

- (void)didLeaveController

Declared In

KKBehavior.h

internal_joinController:withKey:

- (void)internal_joinController:(KKNodeController *)controller withKey:(NSString *)key

isEqualToBehavior:

- (BOOL)isEqualToBehavior:(KKBehavior *)behavior

postNotificationName:

Posts a notification to notification center, with userInfo “behavior” key pointing to the sending behavior object.

- (void)postNotificationName:(NSString *)name

Parameters

name

The uniquely identifying name of the notification.

Declared In

KKBehavior.h

postNotificationName:userInfo:

Posts a notification to notification center, with userInfo “behavior” key pointing to the sending behavior object, and custom userInfo keys.

- (void)postNotificationName:(NSString *)name userInfo:(NSDictionary *)userInfo

Parameters

name

The uniquely identifying name of the notification.

userInfo

A dictionary with custom key/value which the notification receiver may need. A key “behavior” containing the sending behavior object is always added to the dictionary.

Declared In

KKBehavior.h

removeFromNode

Removes the behavior from its owning node and controller.

- (void)removeFromNode

Declared In

KKBehavior.h