00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #import "CCNode.h"
00028 #import "CCProtocols.h"
00029 #import "CCTextureAtlas.h"
00030
00031 @class CCSpriteSheet;
00032 @class CCSpriteFrame;
00033 @class CCAnimation;
00034
00035 #pragma mark CCSprite
00036
00037 enum {
00039 CCSpriteIndexNotInitialized = 0xffffffff,
00040 };
00041
00048 typedef enum {
00050 CC_HONOR_PARENT_TRANSFORM_TRANSLATE = 1 << 0,
00052 CC_HONOR_PARENT_TRANSFORM_ROTATE = 1 << 1,
00054 CC_HONOR_PARENT_TRANSFORM_SCALE = 1 << 2,
00055
00057 CC_HONOR_PARENT_TRANSFORM_ALL = CC_HONOR_PARENT_TRANSFORM_TRANSLATE | CC_HONOR_PARENT_TRANSFORM_ROTATE | CC_HONOR_PARENT_TRANSFORM_SCALE,
00058
00059 } ccHonorParentTransform;
00060
00082 @interface CCSprite : CCNode <CCRGBAProtocol, CCTextureProtocol>
00083 {
00084
00085
00086
00087
00088 CCTextureAtlas *textureAtlas_;
00089 NSUInteger atlasIndex_;
00090 CCSpriteSheet *spriteSheet_;
00091 ccHonorParentTransform honorParentTransform_;
00092 BOOL dirty_;
00093 BOOL recursiveDirty_;
00094 BOOL hasChildren_;
00095
00096
00097
00098
00099 ccBlendFunc blendFunc_;
00100 CCTexture2D *texture_;
00101
00102
00103
00104
00105
00106
00107 BOOL usesSpriteSheet_;
00108
00109
00110 CGRect rect_;
00111
00112
00113 CGPoint offsetPosition_;
00114 CGPoint unflippedOffsetPositionFromCenter_;
00115
00116
00117 ccV3F_C4B_T2F_Quad quad_;
00118
00119
00120 GLubyte opacity_;
00121 ccColor3B color_;
00122 ccColor3B colorUnmodified_;
00123 BOOL opacityModifyRGB_;
00124
00125
00126 BOOL flipX_;
00127 BOOL flipY_;
00128
00129
00130
00131 NSMutableDictionary *animations_;
00132 }
00133
00135 @property (nonatomic,readwrite) BOOL dirty;
00137 @property (nonatomic,readonly) ccV3F_C4B_T2F_Quad quad;
00139 @property (nonatomic,readwrite) NSUInteger atlasIndex;
00141 @property (nonatomic,readonly) CGRect textureRect;
00149 @property (nonatomic,readwrite) BOOL flipX;
00157 @property (nonatomic,readwrite) BOOL flipY;
00159 @property (nonatomic,readwrite) GLubyte opacity;
00161 @property (nonatomic,readwrite) ccColor3B color;
00163 @property (nonatomic,readwrite) BOOL usesSpriteSheet;
00165 @property (nonatomic,readwrite,assign) CCTextureAtlas *textureAtlas;
00167 @property (nonatomic,readwrite,assign) CCSpriteSheet *spriteSheet;
00173 @property (nonatomic,readwrite) ccHonorParentTransform honorParentTransform;
00177 @property (nonatomic,readonly) CGPoint offsetPosition;
00179 @property (nonatomic,readwrite) ccBlendFunc blendFunc;
00180
00181 #pragma mark CCSprite - Initializers
00182
00187 +(id) spriteWithTexture:(CCTexture2D*)texture;
00188
00192 +(id) spriteWithTexture:(CCTexture2D*)texture rect:(CGRect)rect;
00193
00196 +(id) spriteWithTexture:(CCTexture2D*)texture rect:(CGRect)rect offset:(CGPoint)offset;
00197
00200 +(id) spriteWithSpriteFrame:(CCSpriteFrame*)spriteFrame;
00201
00207 +(id) spriteWithSpriteFrameName:(NSString*)spriteFrameName;
00208
00213 +(id) spriteWithFile:(NSString*)filename;
00214
00218 +(id) spriteWithFile:(NSString*)filename rect:(CGRect)rect;
00219
00223 +(id) spriteWithCGImage: (CGImageRef)image DEPRECATED_ATTRIBUTE;
00224
00231 +(id) spriteWithCGImage: (CGImageRef)image key:(NSString*)key;
00232
00233
00236 +(id) spriteWithSpriteSheet:(CCSpriteSheet*)spritesheet rect:(CGRect)rect;
00237
00238
00243 -(id) initWithTexture:(CCTexture2D*)texture;
00244
00248 -(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect;
00249
00252 -(id) initWithSpriteFrame:(CCSpriteFrame*)spriteFrame;
00253
00259 -(id) initWithSpriteFrameName:(NSString*)spriteFrameName;
00260
00265 -(id) initWithFile:(NSString*)filename;
00266
00270 -(id) initWithFile:(NSString*)filename rect:(CGRect)rect;
00271
00275 -(id) initWithCGImage: (CGImageRef)image DEPRECATED_ATTRIBUTE;
00276
00283 -(id) initWithCGImage:(CGImageRef)image key:(NSString*)key;
00284
00287 -(id) initWithSpriteSheet:(CCSpriteSheet*)spritesheet rect:(CGRect)rect;
00288
00289
00290 #pragma mark CCSprite - SpriteSheet methods
00291
00294 -(void)updateTransform;
00295
00298 -(void) setTextureRect:(CGRect) rect;
00299
00303 -(void) useSelfRender;
00304
00308 -(void) useSpriteSheetRender:(CCSpriteSheet*)spriteSheet;
00309
00310
00311 #pragma mark CCSprite - Frames
00312
00314 -(void) setDisplayFrame:(CCSpriteFrame*)newFrame;
00315
00317 -(BOOL) isFrameDisplayed:(CCSpriteFrame*)frame;
00318
00320 -(CCSpriteFrame*) displayedFrame;
00321
00322 #pragma mark CCSprite - Animation
00323
00325 -(void) setDisplayFrame: (NSString*) animationName index:(int) frameIndex;
00326
00328 -(CCAnimation*)animationByName: (NSString*) animationName;
00329
00331 -(void) addAnimation: (CCAnimation*) animation;
00332
00333 @end