-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCCMaskTo.m
More file actions
52 lines (40 loc) · 1.38 KB
/
CCMaskTo.m
File metadata and controls
52 lines (40 loc) · 1.38 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
//
// CCMaskTo.m
//
// Created by georgejcook
//
#import "CCMaskTo.h"
@implementation CCMaskTo
+(id) actionWithDuration: (ccTime)t rect: (CGRect)r {
return [[[self alloc] initWithDuration:t rect:r ] autorelease];
}
-(id) initWithDuration: (ccTime)t rect: (CGRect)r {
if(!(self = [super initWithDuration: t]))
return nil;
endRect = r;
return self;
}
-(void) startWithTarget:(id)aTarget {
DLog(@"target:::::::: %@", aTarget);
[super startWithTarget:aTarget];
startRect = [target textureRect];
CGPoint endXY = ccp(endRect.origin.x, endRect.origin.y);
CGPoint endWH = ccp(endRect.size.width, endRect.size.height);
CGPoint startXY = ccp(startRect.origin.x, startRect.origin.y);
CGPoint startWH = ccp(startRect.size.width, startRect.size.height);
CGPoint deltaXY = ccpSub( endXY, startXY );
CGPoint deltaWH = ccpSub( endWH, startWH );
delta = CGRectMake(deltaXY.x, deltaXY.y, deltaWH.x, deltaWH.y);
}
-(id) copyWithZone: (NSZone *)zone {
CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] rect: endRect];
return copy;
}
-(void) update: (ccTime)t {
CGRect newTextureRect = CGRectMake(
(startRect.origin.x + delta.origin.x * t ), (startRect.origin.y + delta.origin.y * t ),
(startRect.size.width + delta.size.width * t ), (startRect.size.height + delta.size.height * t )
);
[target setTextureRect: newTextureRect];
}
@end