Skip to content

Instantly share code, notes, and snippets.

@britg
Created June 18, 2011 01:49
Show Gist options
  • Save britg/1032712 to your computer and use it in GitHub Desktop.
Save britg/1032712 to your computer and use it in GitHub Desktop.
MultistrokeGestureRecognizer-iOS
- (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView: [touch view]];
[glyphDetector addPoint:point];
}
- (void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView: [touch view]];
[glyphDetector addPoint:point];
}
- (void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView: [touch view]];
[glyphDetector addPoint:point];
[glyphDetector detectGlyph];
}
[
[ [345,9], [345,87] ],
[ [351,8], [363,8], [372, 9], [380, 11], [386, 14], [391, 17], [394, 22], [397, 28], [399,34], [400,42], [400,50], [400,56], [399,61], [397,66], [394,70], [391,74], [386,78], [382,81], [377,83], [372,85], [367,87], [360,87], [355,88], [349,87] ]
]
// The Detector delegate should implement this method:
- (void)glyphDetected:(WTMGlyph *)glyph withScore:(float)score {
// Go forth and do awesome things
}
#import "WTMGlyphDetector.h"
// MyDetectingThing.h
@interface SpellInputLayer : CCLayer <WTMGlyphDelegate> {
WTMGlyphDetector *glyphDetector;
}
// MyDetectingThing.m
// An example method in an object that initializes the
// gesture detector
- (void)initGestureDetector {
// Initialize
glyphDetector = [WTMGlyphDetector detector];
// Assign the detection delegate
glyphDetector.delegate = self;
// Add initial glyph templates from JSON files
// Rinse and repeat for each of the gestures you want to detect
NSData *jsonData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"D" ofType:@"json"]];
[self addGlyphFromJSON:jsonData name:@"D"];
}
@torinnguyen
Copy link

There is a small mistake here: [self addGlyphFromJSON:jsonData name:@"D"];
It should be
[glyphDetector addGlyphFromJSON:jsonData name:@"D"];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment