Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
users:shilo:extensions:shshakeevent [2012/08/21 00:34]
67.181.243.216 [Data entry]
users:shilo:extensions:shshakeevent [2013/03/05 10:19] (current)
Line 1: Line 1:
 +====== SHShakeEvent ======
 +---- dataentry extension ----
 +type          : extension
 +author_mail ​  : shilo86@gmail.com Shilo White
 +description ​  : A simple shake event.
 +lastupdate_dt : 2011-03-20
 +compatible ​   : v1.X
 +depends ​      : ​
 +tags          : shake, event, shakeevent
 +homepage_url ​ : https://​gist.github.com/​878254
 +download_url ​ : https://​gist.github.com/​gists/​878254/​download
 +sample_url ​   : http://​shilo.coarsemode.com/​sparrow/​extensions/​shshakeevent/​DontWakeSparrowSample.zip
 +----
  
 +===== Description =====
 +SHShakeEvent class will allow you to easily listen to shake events inside Sparrow.
 +
 +===== Sample =====
 +[[http://​shilo.coarsemode.com/​sparrow/​extensions/​shshakeevent/​DontWakeSparrowSample.zip|{{http://​shilo.coarsemode.com/​sparrow/​extensions/​shshakeevent/​DontWakeSparrowScreenshot.png}}]]
 +  * Project: [[http://​shilo.coarsemode.com/​sparrow/​extensions/​shshakeevent/​DontWakeSparrowSample.zip|Don'​t Wake Sparrow]]
 +  * Screenshot: [[http://​shilo.coarsemode.com/​sparrow/​extensions/​shshakeevent/​DontWakeSparrowScreenshot.png|DontWakeSparrowScreenshot.png]]
 +  * Recording: [[http://​shilo.coarsemode.com/​sparrow/​extensions/​shshakeevent/​DontWakeSparrowRecording.mov|DontWakeSparrowRecording.mov]]
 +
 +===== Example =====
 +<code objc>
 +@implementation Game
 +- (id)initWithWidth:​(float)width height:​(float)height {
 + if (self = [super initWithWidth:​width height:​height]) {
 + [self addEventListener:​@selector(onShake:​) atObject:​self forType:​SH_EVENT_TYPE_SHAKE];​
 +    }
 +   ​ return self;
 +}
 + 
 +- (void)onShake:​(SHShakeEvent *)event {
 + if (event.phase == SHShakePhaseBegan) {
 + NSLog(@"​Shake began"​);​
 + } else if (event.phase == SHShakePhaseEnded) {
 + NSLog(@"​Shake ended"​);​
 + } else if (event.phase == SHShakePhaseCancelled) {
 + NSLog(@"​Shake cancelled"​);​
 + }
 +}
 + 
 +- (void)dealloc {
 + [self removeEventListener:​@selector(onShake:​) atObject:​self forType:​SH_EVENT_TYPE_SHAKE];​
 + [super dealloc];
 +}
 +@end
 +</​code>​
 +
 +===== Instructions =====
 +==== To add into your Sparrow project ====
 +  - Download the source files here: [[https://​gist.github.com/​gists/​878254/​download]]
 +  - Open your desired Sparrow project
 +  - Drag and drop the files into the "​Groups & Files" pane
 +  - Open "​Game.h"​
 +  - Include the extension: <code objc>#​include "​SHShakeEvent.h"</​code>​
 +  - Save "​Game.h"​
 +
 +==== To add directly into Sparrow source ====
 +  - Download the source files here: [[https://​gist.github.com/​gists/​878254/​download]]
 +  - Save the files into Sparrow'​s "/​Classes/"​ directory
 +    * Example: "/​sparrow/​src/​Classes/"​
 +  - Navigate back one directory and open "​Sparrow.xcodeproj"​
 +    * Example: "/​sparrow/​src/​Sparrow.xcodeproj"​
 +  - Inside the "​Groups & Files" pane, locate the "​Events"​ group folder
 +    * Example: "​Sparrow -> Classes -> Events"​
 +  - Right click the "​Display"​ group folder and click "Add -> Existing Files.."​
 +  - Navigate into the "/​Classes/"​ directory and select "​SHShakeEvent.h"​ and "​SHShakeEvent.m",​ then click "​add"​
 +  - On the next window, leave all options as default and click "​add"​
 +  - In the "​Groups & Files" pane, Open "​Sparrow.h"​
 +    * Example "​Sparrow -> Classes -> Sparrow.h"​
 +  - At the bottom of the file, add: <code objc>#​import "​SHShakeEvent.h"</​code>​
 +  - Save "​Sparrow.h"​
 +  - Close "​Sparrow.xcodeproj"​
 +
 +===== Source Code =====
 +%gist(878254)%
 +
 +===== Changelog =====
 +  * //​2011-03-08://​ First version
 +
 +===== Todo =====
 +  * (EMPTY)
 +
 +===== Special Thanks =====
 +  * [[http://​forum.sparrow-framework.org/​profile/​daniel|Daniel]] for helping me improve the initialization
 
 
Powered by DokuWiki