SHShakeEvent
Description
SHShakeEvent class will allow you to easily listen to shake events inside Sparrow.
Sample
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
-
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
-
Save the files into Sparrow's “/Classes/” directory
Navigate back one directory and open “Sparrow.xcodeproj”
Inside the “Groups & Files” pane, locate the “Events” group folder
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”
At the bottom of the file, add:
#import "SHShakeEvent.h"
Save “Sparrow.h”
Close “Sparrow.xcodeproj”
Source Code
Changelog
Todo
Special Thanks
Daniel for helping me improve the initialization