|
cocos2d for iPhone 1.0.0
2D engine for iOS and OS X
|
00001 /* 00002 * cocos2d for iPhone: http://www.cocos2d-iphone.org 00003 * 00004 * Copyright (c) 2008-2010 Ricardo Quesada 00005 * Copyright (c) 2011 Zynga Inc. 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a copy 00008 * of this software and associated documentation files (the "Software"), to deal 00009 * in the Software without restriction, including without limitation the rights 00010 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00011 * copies of the Software, and to permit persons to whom the Software is 00012 * furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included in 00015 * all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00020 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00022 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00023 * THE SOFTWARE. 00024 * 00025 */ 00026 00027 00028 #import "CCNode.h" 00029 #import "CCProtocols.h" 00030 #import "CCTextureAtlas.h" 00031 00032 @class CCSpriteBatchNode; 00033 @class CCSpriteFrame; 00034 @class CCAnimation; 00035 00036 #pragma mark CCSprite 00037 00038 #define CCSpriteIndexNotInitialized 0xffffffff /// CCSprite invalid index on the CCSpriteBatchode 00039 00046 typedef enum { 00048 CC_HONOR_PARENT_TRANSFORM_TRANSLATE = 1 << 0, 00050 CC_HONOR_PARENT_TRANSFORM_ROTATE = 1 << 1, 00052 CC_HONOR_PARENT_TRANSFORM_SCALE = 1 << 2, 00054 CC_HONOR_PARENT_TRANSFORM_SKEW = 1 << 3, 00055 00057 CC_HONOR_PARENT_TRANSFORM_ALL = CC_HONOR_PARENT_TRANSFORM_TRANSLATE | CC_HONOR_PARENT_TRANSFORM_ROTATE | CC_HONOR_PARENT_TRANSFORM_SCALE | CC_HONOR_PARENT_TRANSFORM_SKEW, 00058 00059 } ccHonorParentTransform; 00060 00083 @interface CCSprite : CCNode <CCRGBAProtocol, CCTextureProtocol> 00084 { 00085 00086 // 00087 // Data used when the sprite is rendered using a CCSpriteBatchNode 00088 // 00089 CCTextureAtlas *textureAtlas_; // Sprite Sheet texture atlas (weak reference) 00090 NSUInteger atlasIndex_; // Absolute (real) Index on the batch node 00091 CCSpriteBatchNode *batchNode_; // Used batch node (weak reference) 00092 ccHonorParentTransform honorParentTransform_; // whether or not to transform according to its parent transformations 00093 BOOL dirty_; // Sprite needs to be updated 00094 BOOL recursiveDirty_; // Subchildren needs to be updated 00095 BOOL hasChildren_; // optimization to check if it contain children 00096 00097 // 00098 // Data used when the sprite is self-rendered 00099 // 00100 ccBlendFunc blendFunc_; // Needed for the texture protocol 00101 CCTexture2D *texture_; // Texture used to render the sprite 00102 00103 // 00104 // Shared data 00105 // 00106 00107 // whether or not it's parent is a CCSpriteBatchNode 00108 BOOL usesBatchNode_; 00109 00110 // texture 00111 CGRect rect_; 00112 CGRect rectInPixels_; 00113 BOOL rectRotated_; 00114 00115 // Offset Position (used by Zwoptex) 00116 CGPoint offsetPositionInPixels_; 00117 CGPoint unflippedOffsetPositionFromCenter_; 00118 00119 // vertex coords, texture coords and color info 00120 ccV3F_C4B_T2F_Quad quad_; 00121 00122 // opacity and RGB protocol 00123 GLubyte opacity_; 00124 ccColor3B color_; 00125 ccColor3B colorUnmodified_; 00126 BOOL opacityModifyRGB_; 00127 00128 // image is flipped 00129 BOOL flipX_; 00130 BOOL flipY_; 00131 00132 00133 // Animations that belong to the sprite 00134 NSMutableDictionary *animations_; 00135 00136 @public 00137 // used internally. 00138 void (*updateMethod)(id, SEL); 00139 } 00140 00142 @property (nonatomic,readwrite) BOOL dirty; 00144 @property (nonatomic,readonly) ccV3F_C4B_T2F_Quad quad; 00146 @property (nonatomic,readwrite) NSUInteger atlasIndex; 00148 @property (nonatomic,readonly) CGRect textureRect; 00150 @property (nonatomic,readonly) BOOL textureRectRotated; 00158 @property (nonatomic,readwrite) BOOL flipX; 00166 @property (nonatomic,readwrite) BOOL flipY; 00168 @property (nonatomic,readwrite) GLubyte opacity; 00170 @property (nonatomic,readwrite) ccColor3B color; 00172 @property (nonatomic,readwrite) BOOL usesBatchNode; 00174 @property (nonatomic,readwrite,assign) CCTextureAtlas *textureAtlas; 00176 @property (nonatomic,readwrite,assign) CCSpriteBatchNode *batchNode; 00182 @property (nonatomic,readwrite) ccHonorParentTransform honorParentTransform; 00186 @property (nonatomic,readonly) CGPoint offsetPositionInPixels; 00188 @property (nonatomic,readwrite) ccBlendFunc blendFunc; 00189 00190 #pragma mark CCSprite - Initializers 00191 00196 +(id) spriteWithTexture:(CCTexture2D*)texture; 00197 00201 +(id) spriteWithTexture:(CCTexture2D*)texture rect:(CGRect)rect; 00202 00205 +(id) spriteWithSpriteFrame:(CCSpriteFrame*)spriteFrame; 00206 00212 +(id) spriteWithSpriteFrameName:(NSString*)spriteFrameName; 00213 00218 +(id) spriteWithFile:(NSString*)filename; 00219 00223 +(id) spriteWithFile:(NSString*)filename rect:(CGRect)rect; 00224 00231 +(id) spriteWithCGImage: (CGImageRef)image key:(NSString*)key; 00232 00233 00236 +(id) spriteWithBatchNode:(CCSpriteBatchNode*)batchNode 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 00278 -(id) initWithCGImage:(CGImageRef)image key:(NSString*)key; 00279 00282 -(id) initWithBatchNode:(CCSpriteBatchNode*)batchNode rect:(CGRect)rect; 00283 00287 -(id) initWithBatchNode:(CCSpriteBatchNode*)batchNode rectInPixels:(CGRect)rect; 00288 00289 00290 00291 #pragma mark CCSprite - BatchNode methods 00292 00295 -(void)updateTransform; 00296 00299 -(void) setTextureRect:(CGRect) rect; 00302 -(void) setTextureRectInPixels:(CGRect)rect rotated:(BOOL)rotated untrimmedSize:(CGSize)size; 00303 00307 -(void) useSelfRender; 00308 00312 -(void) useBatchNode:(CCSpriteBatchNode*)batchNode; 00313 00314 00315 #pragma mark CCSprite - Frames 00316 00318 -(void) setDisplayFrame:(CCSpriteFrame*)newFrame; 00319 00321 -(BOOL) isFrameDisplayed:(CCSpriteFrame*)frame; 00322 00324 -(CCSpriteFrame*) displayedFrame; 00325 00326 #pragma mark CCSprite - Animation 00327 00331 -(void) setDisplayFrame: (NSString*) animationName index:(int) frameIndex DEPRECATED_ATTRIBUTE; 00332 00337 -(void) setDisplayFrameWithAnimationName:(NSString*)animationName index:(int) frameIndex; 00338 00343 -(CCAnimation*)animationByName: (NSString*) animationName DEPRECATED_ATTRIBUTE; 00344 00349 -(void) addAnimation: (CCAnimation*) animation DEPRECATED_ATTRIBUTE; 00350 00351 @end