summary refs log tree commit diff stats
path: root/libs/cocos2d/CCAnimation.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
committerStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
commit9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch)
tree5bac45ae5157a1cb10c6e45500cbf72789917980 /libs/cocos2d/CCAnimation.m
downloadcartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip
Initial commit (version 0.2.1)
Diffstat (limited to 'libs/cocos2d/CCAnimation.m')
-rwxr-xr-xlibs/cocos2d/CCAnimation.m153
1 files changed, 153 insertions, 0 deletions
diff --git a/libs/cocos2d/CCAnimation.m b/libs/cocos2d/CCAnimation.m new file mode 100755 index 0000000..eb674c6 --- /dev/null +++ b/libs/cocos2d/CCAnimation.m
@@ -0,0 +1,153 @@
1/*
2 * cocos2d for iPhone: http://www.cocos2d-iphone.org
3 *
4 * Copyright (c) 2008-2010 Ricardo Quesada
5 * Copyright (c) 2011 Zynga Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 */
26
27#import "ccMacros.h"
28#import "CCAnimation.h"
29#import "CCSpriteFrame.h"
30#import "CCTexture2D.h"
31#import "CCTextureCache.h"
32
33@implementation CCAnimation
34@synthesize name = name_, delay = delay_, frames = frames_;
35
36+(id) animation
37{
38 return [[[self alloc] init] autorelease];
39}
40
41+(id) animationWithFrames:(NSArray*)frames
42{
43 return [[[self alloc] initWithFrames:frames] autorelease];
44}
45
46+(id) animationWithFrames:(NSArray*)frames delay:(float)delay
47{
48 return [[[self alloc] initWithFrames:frames delay:delay] autorelease];
49}
50
51+(id) animationWithName:(NSString*)name
52{
53 return [[[self alloc] initWithName:name] autorelease];
54}
55
56+(id) animationWithName:(NSString*)name frames:(NSArray*)frames
57{
58 return [[[self alloc] initWithName:name frames:frames] autorelease];
59}
60
61+(id) animationWithName:(NSString*)aname delay:(float)d frames:(NSArray*)array
62{
63 return [[[self alloc] initWithName:aname delay:d frames:array] autorelease];
64}
65
66+(id) animationWithName:(NSString*)aname delay:(float)d
67{
68 return [[[self alloc] initWithName:aname delay:d] autorelease];
69}
70
71-(id) init
72{
73 return [self initWithFrames:nil delay:0];
74}
75
76-(id) initWithFrames:(NSArray*)frames
77{
78 return [self initWithFrames:frames delay:0];
79}
80
81-(id) initWithFrames:(NSArray*)array delay:(float)delay
82{
83 if( (self=[super init]) ) {
84
85 delay_ = delay;
86 self.frames = [NSMutableArray arrayWithArray:array];
87 }
88 return self;
89}
90
91-(id) initWithName:(NSString*)name
92{
93 return [self initWithName:name delay:0 frames:nil];
94}
95
96-(id) initWithName:(NSString*)name frames:(NSArray*)frames
97{
98 return [self initWithName:name delay:0 frames:frames];
99}
100
101-(id) initWithName:(NSString*)t delay:(float)d
102{
103 return [self initWithName:t delay:d frames:nil];
104}
105
106-(id) initWithName:(NSString*)name delay:(float)delay frames:(NSArray*)array
107{
108 if( (self=[super init]) ) {
109
110 delay_ = delay;
111 self.name = name;
112 self.frames = [NSMutableArray arrayWithArray:array];
113 }
114 return self;
115}
116
117- (NSString*) description
118{
119 return [NSString stringWithFormat:@"<%@ = %08X | frames=%d, delay:%f>", [self class], self,
120 [frames_ count],
121 delay_
122 ];
123}
124
125-(void) dealloc
126{
127 CCLOGINFO( @"cocos2d: deallocing %@",self);
128 [name_ release];
129 [frames_ release];
130 [super dealloc];
131}
132
133-(void) addFrame:(CCSpriteFrame*)frame
134{
135 [frames_ addObject:frame];
136}
137
138-(void) addFrameWithFilename:(NSString*)filename
139{
140 CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:filename];
141 CGRect rect = CGRectZero;
142 rect.size = texture.contentSize;
143 CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:texture rect:rect];
144 [frames_ addObject:frame];
145}
146
147-(void) addFrameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect
148{
149 CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:texture rect:rect];
150 [frames_ addObject:frame];
151}
152
153@end