====== 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 ===== @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 ===== 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: #include "SHShakeEvent.h" - 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: #import "SHShakeEvent.h" - 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