SPTouchEvent Class Reference
Inherits from | SPEvent : NSObject |
Declared in | SPTouchEvent.h |
Overview
When one or more fingers touch the screen, move around or are raised, an SPTouchEvent is triggered.
The event contains a list of all touches that are currently present. Each individual touch is
stored in an object of type “Touch”. Since you are normally only interested in the touches
that occurred on top of certain objects, you can query the event for touches with a
specific target through the touchesWithTarget:
method. In this context, the target of a
touch is not only the object that was touched (e.g. an SPImage), but also each of its parents -
e.g. the container that holds that image.
Here is an example of how to react on touch events at ‘self’, which could be a subclass of SPSprite:
// e.g. in 'init'
[self addEventListener:@selector(onTouch:) atObject:self forType:SPEventTypeTouch];
// the corresponding listener:
- (void)onTouch:(SPTouchEvent *)event
{
// query all touches that are currently moving on top of 'self'
NSArray *touches = [[event touchesWithTarget:self andPhase:SPTouchPhaseMoved] allObjects];
if (touches.count == 1)
{
// one finger touching
SPTouch *touch = [touches objectAtIndex:0];
SPPoint *currentPos = [touch locationInSpace:self.parent];
SPPoint *previousPos = [touch previousLocationInSpace:self.parent];
// ...
}
else if (touches.count >= 2)
{
// two fingers touching
// ...
}
}
Tasks
Initialization
-
– initWithType:bubbles:touches:
Creates a touch event with a set of touches. Designated Initializer.
-
– initWithType:touches:
Creates a touch event with a set of touches.
-
+ eventWithType:touches:
Factory method.
Methods
-
– touchesWithTarget:
Gets a set of SPTouch objects that originated over a certain target.
-
– touchesWithTarget:andPhase:
Gets a set of SPTouch objects that originated over a certain target and are in a certain phase.
Properties
Properties
Instance Methods
initWithType:bubbles:touches:
Creates a touch event with a set of touches. Designated Initializer.
- (instancetype)initWithType:(NSString *)type bubbles:(BOOL)bubbles touches:(NSSet *)touches
Discussion
Creates a touch event with a set of touches. Designated Initializer.
Declared In
SPTouchEvent.h
initWithType:touches:
Creates a touch event with a set of touches.
- (instancetype)initWithType:(NSString *)type touches:(NSSet *)touches
Discussion
Creates a touch event with a set of touches.
Declared In
SPTouchEvent.h
touchesWithTarget:
Gets a set of SPTouch objects that originated over a certain target.
- (NSSet *)touchesWithTarget:(SPDisplayObject *)target
Discussion
Gets a set of SPTouch objects that originated over a certain target.
Declared In
SPTouchEvent.h
touchesWithTarget:andPhase:
Gets a set of SPTouch objects that originated over a certain target and are in a certain phase.
- (NSSet *)touchesWithTarget:(SPDisplayObject *)target andPhase:(SPTouchPhase)phase
Discussion
Gets a set of SPTouch objects that originated over a certain target and are in a certain phase.
Declared In
SPTouchEvent.h