SHShakeEvent

type:
extension
author:
Shilo White
description:
A simple shake event.
lastupdate:
2011-03-20
compatible:
v1.X
tag:
shake, event, shakeevent
homepage:
https://gist.github.com/878254
download:
https://gist.github.com/gists/878254/download
sample:
http://shilo.coarsemode.com/sparrow/extensions/shshakeevent/DontWakeSparrowSample.zip

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

  1. Download the source files here: https://gist.github.com/gists/878254/download
  2. Open your desired Sparrow project
  3. Drag and drop the files into the “Groups & Files” pane
  4. Open “Game.h”
  5. Include the extension:
    #include "SHShakeEvent.h"
  6. Save “Game.h”

To add directly into Sparrow source

  1. Download the source files here: https://gist.github.com/gists/878254/download
  2. Save the files into Sparrow's “/Classes/” directory
    • Example: “/sparrow/src/Classes/”
  3. Navigate back one directory and open “Sparrow.xcodeproj”
    • Example: “/sparrow/src/Sparrow.xcodeproj”
  4. Inside the “Groups & Files” pane, locate the “Events” group folder
    • Example: “Sparrow → Classes → Events”
  5. Right click the “Display” group folder and click “Add → Existing Files..”
  6. Navigate into the “/Classes/” directory and select “SHShakeEvent.h” and “SHShakeEvent.m”, then click “add”
  7. On the next window, leave all options as default and click “add”
  8. In the “Groups & Files” pane, Open “Sparrow.h”
    • Example “Sparrow → Classes → Sparrow.h”
  9. At the bottom of the file, add:
    #import "SHShakeEvent.h"
  10. Save “Sparrow.h”
  11. Close “Sparrow.xcodeproj”

Source Code

Changelog

  • 2011-03-08: First version

Todo

  • (EMPTY)

Special Thanks

  • Daniel for helping me improve the initialization
  users/shilo/extensions/shshakeevent.txt · Last modified: 2013/03/05 10:19 by 127.0.0.1
 
Powered by DokuWiki