forked from sceresia/CCAutoType
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCAutoTypeLabelBM.m
More file actions
80 lines (66 loc) · 1.76 KB
/
CCAutoTypeLabelBM.m
File metadata and controls
80 lines (66 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// CCLabelBMAutoType.m
// CCInvaders
//
// Created by Stephen Ceresia on 12-07-03.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "CCAutoTypeLabelBM.h"
@implementation CCAutoTypeLabelBM
@synthesize arrayOfCharacters;
@synthesize autoTypeString;
@synthesize delegate;
- (void) typeText:(NSString*) txt withDelay:(float) d
{
arrayOfCharacters = [[NSMutableArray alloc]init];
autoTypeString = [[NSString alloc]initWithString:txt];
for (int j=1; j < [txt length]+1; ++j)
{
NSString *substring = [txt substringToIndex:j];
[arrayOfCharacters addObject:substring];
}
float delay = d;
for (int i=0; i < [txt length]; ++i)
{
NSString *string = [arrayOfCharacters objectAtIndex:i];
CCSequence *seq = [CCSequence actions:
[CCDelayTime actionWithDuration:i*delay],
[CCCallFuncND actionWithTarget:self selector:@selector(type:data:) data:(NSString*)string],
nil];
[self runAction:seq];
}
[self schedule:@selector(finishCheck:) interval:1];
}
- (void) type:(id) sender data:(NSString*) s
{
[self setString:s];
//NSLog(@"auto typing %@",s);
}
- (void) finishCheck:(ccTime)dt
{
if ([self numberOfRunningActions] == 0)
{
[self unschedule:@selector(finishCheck:)];
[self done:self];
}
}
- (void) done:(id) sender
{
if ([delegate respondsToSelector:@selector(typingFinished:)])
{
[delegate typingFinished:self];
}
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
NSLog(@"me!");
return YES;
}
- (void) dealloc
{
self.delegate = nil;
[arrayOfCharacters release];
[autoTypeString release];
[super dealloc];
}
@end