CCControl Class Reference
Inherits from | CCLayer |
Conforms to | CCRGBAProtocol |
Declared in | CCControl.h |
Overview
CCControl is inspired by the UIControl API class from the UIKit library of CocoaTouch. It provides a base class for Cocos2D control such as CCControlButton or CCControlSlider that convey user intent to the application.
The goal of CCControl is to define an interface and a base implementation for preparing action messages and initially dispatching them to their targets when certain events occur.
To use the CCControl class you have to subclass it and implement your own behavior.
Tasks
RGBA Protocol Properties
-
opacity
Conforms to CCRGBAProtocol protocol.
property -
displayedOpacity
Conforms to CCRGBAProtocol (v2.1) protocol.
property -
color
Conforms to CCRGBAProtocol protocol.
property -
displayedColor
Conforms to CCRGBAProtocol (v2.1) protocol.
property -
opacityModifyRGB
Conforms to CCRGBAProtocol protocol.
property -
cascadeColorEnabled
Conforms to CCRGBAProtocol (v2.1) protocol.
property -
cascadeOpacityEnabled
Conforms to CCRGBAProtocol (v2.1) protocol.
property
Object Attributes
-
defaultTouchPriority
Changes the priority of the button. The lower the number, the higher the priority.
property -
state
The current control state constant.
property -
enabled
Tells whether the control is enabled.
property -
selected
A Boolean value that determines the control’s selected state.
property -
highlighted
A Boolean value that determines whether the control is highlighted.
property -
hasVisibleParents
True if all of the controls parents are visible
property
Preparing and Sending Action Messages
-
– sendActionsForControlEvents:
Sends action messages for the given control events.
-
– addTarget:action:forControlEvents:
Adds a target and action for a particular event (or events) to an internal dispatch table. The action message may optionnaly include the sender and the event as parameters, in that order. When you call this method, target is not retained.
-
– removeTarget:action:forControlEvents:
Removes a target and action for a particular event (or events) from an internal dispatch table.
Preparing Blocks
-
– setBlock:forControlEvents:
Sets a block for a particular event (or events) to an internal dispatch table.
Tracking Touches and Redrawing Controls
-
– isPointInside:
Returns a boolean value that indicates whether a location is inside the bounds of the receiver.
-
– touchLocation:
Returns a point corresponding to the touh location converted into the control space coordinates.
-
– isTouchInside:
Returns a boolean value that indicates whether a touch is inside the bounds of the receiver. The given touch must be relative to the world.
-
– eventLocation:
Returns a point corresponding to the event location converted into the control space coordinates.
-
– isMouseInside:
Returns a boolean value that indicates whether a mouse is inside the bounds of the receiver. The given mouse event must be relative to the world.
-
– needsLayout
Updates the control layout using its current internal state.
Properties
cascadeColorEnabled
Conforms to CCRGBAProtocol (v2.1) protocol.
@property (nonatomic, getter=isCascadeColorEnabled) BOOL cascadeColorEnabled
Discussion
Conforms to CCRGBAProtocol (v2.1) protocol.
Declared In
CCControl.h
cascadeOpacityEnabled
Conforms to CCRGBAProtocol (v2.1) protocol.
@property (nonatomic, getter=isCascadeOpacityEnabled) BOOL cascadeOpacityEnabled
Discussion
Conforms to CCRGBAProtocol (v2.1) protocol.
Declared In
CCControl.h
color
Conforms to CCRGBAProtocol protocol.
@property (nonatomic, readwrite) ccColor3B color
Discussion
Conforms to CCRGBAProtocol protocol.
Declared In
CCControl.h
defaultTouchPriority
Changes the priority of the button. The lower the number, the higher the priority.
@property (nonatomic, assign) NSInteger defaultTouchPriority
Discussion
Changes the priority of the button. The lower the number, the higher the priority.
Declared In
CCControl.h
displayedColor
Conforms to CCRGBAProtocol (v2.1) protocol.
@property (nonatomic, readonly) ccColor3B displayedColor
Discussion
Conforms to CCRGBAProtocol (v2.1) protocol.
Declared In
CCControl.h
displayedOpacity
Conforms to CCRGBAProtocol (v2.1) protocol.
@property (nonatomic, readonly) GLubyte displayedOpacity
Discussion
Conforms to CCRGBAProtocol (v2.1) protocol.
Declared In
CCControl.h
enabled
Tells whether the control is enabled.
@property (nonatomic, getter=isEnabled) BOOL enabled
Discussion
Tells whether the control is enabled.
Declared In
CCControl.h
hasVisibleParents
True if all of the controls parents are visible
@property (nonatomic, readonly) BOOL hasVisibleParents
Discussion
True if all of the controls parents are visible
Declared In
CCControl.h
highlighted
A Boolean value that determines whether the control is highlighted.
@property (nonatomic, getter=isHighlighted) BOOL highlighted
Discussion
A Boolean value that determines whether the control is highlighted.
Declared In
CCControl.h
opacity
Conforms to CCRGBAProtocol protocol.
@property (nonatomic, readwrite) GLubyte opacity
Discussion
Conforms to CCRGBAProtocol protocol.
Declared In
CCControl.h
opacityModifyRGB
Conforms to CCRGBAProtocol protocol.
@property (nonatomic, getter=doesOpacityModifyRGB) BOOL opacityModifyRGB
Discussion
Conforms to CCRGBAProtocol protocol.
Declared In
CCControl.h
Instance Methods
addTarget:action:forControlEvents:
Adds a target and action for a particular event (or events) to an internal dispatch table. The action message may optionnaly include the sender and the event as parameters, in that order. When you call this method, target is not retained.
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(CCControlEvent)controlEvents
Parameters
- target
The target object—that is, the object to which the action message is sent. It cannot be nil. The target is not retained.
- action
A selector identifying an action message. It cannot be NULL.
- controlEvents
A bitmask specifying the control events for which the action message is sent. See “CCControlEvent” for bitmask constants.
Discussion
Adds a target and action for a particular event (or events) to an internal dispatch table. The action message may optionnaly include the sender and the event as parameters, in that order. When you call this method, target is not retained.
Declared In
CCControl.h
eventLocation:
Returns a point corresponding to the event location converted into the control space coordinates.
- (CGPoint)eventLocation:(NSEvent *)event
Parameters
- event
An NSEvent object representing the event.
Return Value
A point specifying the location of the event in the current control context.
Discussion
Returns a point corresponding to the event location converted into the control space coordinates.
Declared In
CCControl.h
isMouseInside:
Returns a boolean value that indicates whether a mouse is inside the bounds of the receiver. The given mouse event must be relative to the world.
- (BOOL)isMouseInside:(NSEvent *)event
Parameters
- event
An NSEvent object representing the event.
Return Value
YES whether a mouse event is inside the receiver’s rect.
Discussion
Returns a boolean value that indicates whether a mouse is inside the bounds of the receiver. The given mouse event must be relative to the world.
Declared In
CCControl.h
isPointInside:
Returns a boolean value that indicates whether a location is inside the bounds of the receiver.
- (BOOL)isPointInside:(CGPoint)location
Parameters
- location
A CGPoint that represents a location.
Return Value
YES whether a location is inside the receiver’s rect.
Discussion
Returns a boolean value that indicates whether a location is inside the bounds of the receiver.
Declared In
CCControl.h
isTouchInside:
Returns a boolean value that indicates whether a touch is inside the bounds of the receiver. The given touch must be relative to the world.
- (BOOL)isTouchInside:(UITouch *)touch
Parameters
- touch
A UITouch object that represents a touch.
Return Value
YES whether a touch is inside the receiver’s rect.
Discussion
Returns a boolean value that indicates whether a touch is inside the bounds of the receiver. The given touch must be relative to the world.
Declared In
CCControl.h
needsLayout
Updates the control layout using its current internal state.
- (void)needsLayout
Discussion
Updates the control layout using its current internal state.
Declared In
CCControl.h
removeTarget:action:forControlEvents:
Removes a target and action for a particular event (or events) from an internal dispatch table.
- (void)removeTarget:(id)target action:(SEL)action forControlEvents:(CCControlEvent)controlEvents
Parameters
- target
The target object—that is, the object to which the action message is sent. Pass nil to remove all targets paired with action and the specified control events.
- action
A selector identifying an action message. Pass NULL to remove all action messages paired with target.
- controlEvents
A bitmask specifying the control events associated with target and action. See “CCControlEvent” for bitmask constants.
Discussion
Removes a target and action for a particular event (or events) from an internal dispatch table.
Declared In
CCControl.h
sendActionsForControlEvents:
Sends action messages for the given control events.
- (void)sendActionsForControlEvents:(CCControlEvent)controlEvents
Parameters
- controlEvents
A bitmask whose set flags specify the control events for which action messages are sent. See “CCControlEvent” for bitmask constants.
Discussion
Sends action messages for the given control events.
Declared In
CCControl.h
setBlock:forControlEvents:
Sets a block for a particular event (or events) to an internal dispatch table.
- (void)setBlock:(CCControlBlock)block forControlEvents:(CCControlEvent)controlEvents
Parameters
- block
The block to which the action message is sent. If the block is nil, it removes the previous one.
- controlEvents
A bitmask specifying the control events for which the action message is sent. See “CCControlEvent” for bitmask constants.
Discussion
Sets a block for a particular event (or events) to an internal dispatch table.
Declared In
CCControl.h
touchLocation:
Returns a point corresponding to the touh location converted into the control space coordinates.
- (CGPoint)touchLocation:(UITouch *)touch
Parameters
- touch
A UITouch object that represents a touch.
Return Value
A point specifying the location of the touch in the current control context.
Discussion
Returns a point corresponding to the touh location converted into the control space coordinates.
Declared In
CCControl.h