Download Kobold2D v2.x Documentation
Transcript
CCArray* touches = [KKInput sharedInput].touches;
KKTouch* touch;
CCARRAY_FOREACH(touches, touch)
{
// do something with touch here
mySprite.position = touch.location;
}
The KKTouch location and previousLocation properties are already converted to Cocos2D view coordinates. You do not
need to (and shouldn't) call CCDirector's convertGL method.
Each KKTouch object corresponds to a particular finger on the screen. The same KKTouch object is used for the same finger starting when the
touch "began" until the touch either "ended" or got "cancelled".
You can not rely on the array index for accessing a particular finger's KKTouch as other touches may end and get started. You can either store
and later compare the touchID property to make sure you're using the same KKTouch as before, or simply keep a weak reference to the
KKTouch object. In that case you have to check that it's phase property isn't KKTouchPhaseLifted, which indicates that the KKTouch object is
no longer associated with a finger on the screen. You will also want to nil your reference when the touch phase is either KKTouchPhaseEnded or
KKTouchPhaseLifted.
If you ever need access to the underlying UITouch* object, you can simply cast the touchID property:
// access the underlying UITouch object if needed
UITouch* uiTouch = (UITouch*)touch.touchID;
Do not retain or otherwise hold on to UITouch* objects, they may contain invalid data in the next frame. Access them only
through the touches property on a "as needed" basis.
Removing a Touch
As of Kobold2D v1.0.2 you can remove a touch to prevent other classes from handling the same touch. The finger associated with that KKTouch
object will be ignored from then on.
CCArray* touches = [KKInput sharedInput].touches;
KKTouch* touch;
CCARRAY_FOREACH(touches, touch)
{
// remove touch
[[KKInput sharedInput] removeTouch:touch];
}
It is legal to remove touches while iterating over the touches array. The touch is first invalidated ( KKTouchPhase is set to KKTouchPhaseLifted
among other things) and later removed.
KKInput Gestures
KKInput Gesture Recognizer Support
Gestures can influence each other
Testing if Gesture Recognizers are Available
Enabling Gestures
Gesture Location
Discrete Gestures: Tap, Double-Tap and Swipe
Continuous Gestures: LongPress, Pan, Rotation and Pinch
Swipe Gesture Properties
Pan Gesture Properties
Rotation Gesture Properties
Pinch Gesture Properties
Cancelling a Continuous Gesture Recognizer
Accessing the underlying UIGestureRecognizer objects
KKInput Gesture Recognizer Support