This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
users:shilo:extensions:shpinchevent [2012/03/08 09:16] – stopPinchRecognizer, not stopSwipeRecognizer 220.244.216.18 | users:shilo:extensions:shpinchevent [2013/03/05 10:19] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== SHPinchEvent ====== | ||
+ | ---- dataentry extension ---- | ||
+ | type : extension | ||
+ | author_mail | ||
+ | description | ||
+ | lastupdate_dt | ||
+ | compatible | ||
+ | depends | ||
+ | tags : pinch, event, pinchevent | ||
+ | homepage_url | ||
+ | download_url | ||
+ | min iOS version : 3.2 | ||
+ | ---- | ||
+ | ===== Description ===== | ||
+ | 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. | ||
+ | |||
+ | ===== Sample ===== | ||
+ | (Coming later) | ||
+ | |||
+ | ===== Example ===== | ||
+ | <code objc> | ||
+ | @implementation Game | ||
+ | - (id)initWithWidth: | ||
+ | if (self = [super initWithWidth: | ||
+ | //start pinch recognizer | ||
+ | [self.stage startPinchRecognizer]; | ||
+ | |||
+ | SPQuad *quad = [SPQuad quadWithWidth: | ||
+ | |||
+ | //add a swipe event listener | ||
+ | [quad addEventListener: | ||
+ | |||
+ | [self.stage addChild: | ||
+ | } | ||
+ | return self; | ||
+ | } | ||
+ | |||
+ | - (void)onPinch: | ||
+ | SPPoint *localLocation = event.location; | ||
+ | SPPoint *globalLocation = [event locationInSpace: | ||
+ | float scale = event.scale; | ||
+ | float velocity = event.velocity; | ||
+ | uint numberOfTouches = event.numberOfTouches; | ||
+ | } | ||
+ | |||
+ | - (void)dealloc { | ||
+ | //stop and remove pinch recognizer | ||
+ | [self.stage stopPinchRecognizer]; | ||
+ | |||
+ | [self removeChild: | ||
+ | [super dealloc]; | ||
+ | } | ||
+ | @end | ||
+ | </ | ||
+ | |||
+ | ===== Instructions ===== | ||
+ | ==== To add into your Sparrow project ==== | ||
+ | - Download the source files here: [[https:// | ||
+ | - Open your desired Sparrow project | ||
+ | - Drag and drop the files into the " | ||
+ | - Open " | ||
+ | - Include the extension: <code objc># | ||
+ | - Save " | ||
+ | ==== To add directly into Sparrow source ==== | ||
+ | - Download the source files here: [[https:// | ||
+ | - Save the files into Sparrow' | ||
+ | * Example: "/ | ||
+ | - Navigate back one directory and open " | ||
+ | * Example: "/ | ||
+ | - Inside the " | ||
+ | * Example: " | ||
+ | - Right click the " | ||
+ | - Navigate into the "/ | ||
+ | - On the next window, leave all options as default and click " | ||
+ | - In the " | ||
+ | * Example " | ||
+ | - At the bottom of the file, add: <code objc># | ||
+ | - Save " | ||
+ | - Close " | ||
+ | ===== Troubleshooting ===== | ||
+ | ==== Why is it not recognizing Pinches? ==== | ||
+ | Make sure you add this line before listening for a SHPinchEvent: | ||
+ | <code objc> | ||
+ | |||
+ | ==== Why am I getting a runtime error/ | ||
+ | If you are encountering this runtime error: | ||
+ | <code objc>*** Terminating app due to uncaught exception ' | ||
+ | |||
+ | Inside your ApplicationDelegate, | ||
+ | <code objc> | ||
+ | - (BOOL)application: | ||
+ | SP_CREATE_POOL(pool); | ||
+ | |||
+ | [SPStage setSupportHighResolutions: | ||
+ | [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/ | ||
+ | |||
+ | You could also call " | ||
+ | |||
+ | ===== Source Code ===== | ||
+ | %gist(d22c35483be9d7a2b734)% | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | * // | ||
+ | |||
+ | ===== Todo ===== | ||
+ | * (Empty) |