SHPinchEvent class will allow you to easily listen to pinch events inside Sparrow. The event will hold the local touch location, scale, velocity, and number of touches. It also contains a method to get the location based on spaces that inherit SPDisplayObject. Note: SHPinchEvent will only bubble to display objects with bounds containing the touch location.
(Coming later)
@implementation Game - (id)initWithWidth:(float)width height:(float)height { if (self = [super initWithWidth:width height:height]) { //start pinch recognizer [self.stage startPinchRecognizer]; SPQuad *quad = [SPQuad quadWithWidth:50 height:50]; //add a swipe event listener [quad addEventListener:@selector(onPinch:) atObject:self forType:SH_EVENT_TYPE_PINCH]; [self.stage addChild:quad]; } return self; } - (void)onPinch:(SHPinchEvent *)event { SPPoint *localLocation = event.location; SPPoint *globalLocation = [event locationInSpace:self.stage]; float scale = event.scale; float velocity = event.velocity; uint numberOfTouches = event.numberOfTouches; } - (void)dealloc { //stop and remove pinch recognizer [self.stage stopPinchRecognizer]; [self removeChild:mContainer]; [super dealloc]; } @end
#include "SHPinchEvent.h"
#import "SHPinchEvent.h"
Make sure you add this line before listening for a SHPinchEvent:
[self.stage startPinchRecognizer];
If you are encountering this runtime error:
*** Terminating app due to uncaught exception 'NativeViewDoesNotExist', reason: 'nativeView not linked to stage yet.'
Inside your ApplicationDelegate, I suggest you link your Game class to sparrowView (SPView) BEFORE initializing your Game class, like so:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { SP_CREATE_POOL(pool); [SPStage setSupportHighResolutions:YES]; [SPAudioEngine start]; Game *game = [Game alloc]; sparrowView.stage = game; game = [game init]; [game release]; [window makeKeyAndVisible]; [sparrowView start]; SP_RELEASE_POOL(pool); return YES; }
Warning: Although this method works fine in this situation, it might not be safe to get an instance of other Apple/Sparrow classes before initialization. The class might release and initialize a new instance of itself in the “init” method, which would make the old instance invalid.
You could also call “startPinchRecognizer:” method after SPStage is linked to SPView.