Joystick Class Reference
Inherits from | CCLayer : CCNode |
Declared in | Joystick.h |
Overview
A Joystick control constructed from two child CCNodes, one as a movable thumb CCNode that visually simulates the “stick”, and another as an optional background CCNode that provides a backdrop over which the thumb moves.
The user can control the Joystick by touching within the bounds of the Joystick and then dragging the finger around. They thumb image will track the finger within the bounds of the Joystick. When the user raises the finger, the thumb will move in an animated fashion back to its resting position, which is the anchorPoint of the Joystick.
The current position of the thumb can be read using either X-Y coordinates via the velocity property, or angular coordinates via the angularVelocity property.
Properties
angularVelocity
The velocity of the joystick in terms of angular coordinates. The returned heading is measured in degrees from the vertical axis, with positive angles growing clockwise. The radius is clamped to a maximum of unit length. The set of possible points returned by this method therefore covers the area of a circle of unit radius.
@property (nonatomic, readonly) AngularPoint angularVelocity
Declared In
Joystick.h
velocity
The current velocity of the Joystick in terms of cartesian X-Y coordinates, as measured by the current position of the thumb proportionally relative to its resting position (the anchorPoint of the Joystick) and the contentSize of the Joystick. The individual X and Y values may be either positive (up an right) or negative (down and left). The magnitude of the X-Y vector is clamped to unit length, even if the user drags the finger outside the bounds of the Joystick. The set of possible points returned by this property therefore covers the area of a circle of unit radius, centered on the origin of an X-Y plane.
@property (nonatomic, readonly) CGPoint velocity
Declared In
Joystick.h
Class Methods
joystickWithThumb:andBackdrop:
Allocates and initializes an autoreleased Joystick to use the specified nodes to draw the thumb (the “stick”) and background behind the “stick”. The contentSize of the Joystick will be set to that of the backgroundNode.
+ (id)joystickWithThumb:(CCNode *)thumbNode andBackdrop:(CCNode *)backgroundNode
Declared In
Joystick.h
Instance Methods
initWithThumb:andBackdrop:
Initialize this Joystick to use the specified CCNodes to draw the thumb (the “stick”) and background behind the “stick”. The contentSize of the Joystick will be set to that of the backgroundNode.
- (id)initWithThumb:(CCNode *)thumbNode andBackdrop:(CCNode *)backgroundNode
Declared In
Joystick.h