This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
users:shilo:extensions:shswipeevent [2011/05/01 22:50] – [Data entry] 81.34.108.1 | users:shilo:extensions:shswipeevent [2013/03/05 10:19] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== SHSwipeEvent ====== | ||
+ | ---- dataentry extension ---- | ||
+ | type : extension | ||
+ | author_mail | ||
+ | description | ||
+ | lastupdate_dt | ||
+ | compatible | ||
+ | depends | ||
+ | tags : swipe, event, swipeevent | ||
+ | homepage_url | ||
+ | download_url | ||
+ | sample_url | ||
+ | min iOS version : 3.2 | ||
+ | ---- | ||
+ | ===== Description ===== | ||
+ | SHSwipeEvent class will allow you to easily listen to swipe events inside Sparrow, it also contains extra methods to get the location and direction based on spaces that inherit SPDisplayObject. | ||
+ | |||
+ | ===== Sample ===== | ||
+ | [[http:// | ||
+ | * Project: [[http:// | ||
+ | * Screenshot: [[http:// | ||
+ | * Recording: [[http:// | ||
+ | |||
+ | ===== Example ===== | ||
+ | <code objc> | ||
+ | @implementation Game | ||
+ | - (id)initWithWidth: | ||
+ | if (self = [super initWithWidth: | ||
+ | //set a container sprite in landscape | ||
+ | mContainer = [SPSprite sprite]; | ||
+ | mContainer.rotation = SP_D2R(90); | ||
+ | mContainer.x = 320; | ||
+ | [self addChild: | ||
+ | |||
+ | //start swipe recognizer | ||
+ | [self.stage startSwipeRecognizer]; | ||
+ | |||
+ | //add a swipe event listener | ||
+ | [self addEventListener: | ||
+ | } | ||
+ | return self; | ||
+ | } | ||
+ | |||
+ | - (void)onSwipe: | ||
+ | //get the global coordinates from the start of the swipe | ||
+ | SPPoint *globalLocation = event.location; | ||
+ | |||
+ | //get the local coordinates based on mContainer | ||
+ | SPPoint *localLocation = [event locationInSpace: | ||
+ | |||
+ | //get the global swipe direction | ||
+ | SHSwipeDirection globalDirection = event.direction; | ||
+ | |||
+ | //get the local swipe direction based on mContainer | ||
+ | SHSwipeDirection localDirection = [event directionInSpace: | ||
+ | |||
+ | //check the local swipe direction | ||
+ | if (localDirection == SHSwipeDirectionUp) { | ||
+ | NSLog(@" | ||
+ | } else if (localDirection == SHSwipeDirectionDown) { | ||
+ | NSLog(@" | ||
+ | } else if (localDirection == SHSwipeDirectionLeft) { | ||
+ | NSLog(@" | ||
+ | } else if (localDirection == SHSwipeDirectionRight) { | ||
+ | NSLog(@" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | - (void)dealloc { | ||
+ | //stop and remove swipe recognizer | ||
+ | [self.stage stopSwipeRecognizer]; | ||
+ | |||
+ | [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 swipes? ==== | ||
+ | Make sure you add this line before listening for a SPSwipeEvent: | ||
+ | <code objc> | ||
+ | |||
+ | ==== Why is it not recognizing the correct swipe direction? ==== | ||
+ | if you are using " | ||
+ | |||
+ | ==== 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(882536)% | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | * // | ||
+ | * // | ||
+ | |||
+ | ===== Todo ===== | ||
+ | * Add continuous swipe option |