|
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) 2009 Valentin Milea 00005 * 00006 * Copyright (c) 2008-2010 Ricardo Quesada 00007 * Copyright (c) 2011 Zynga Inc. 00008 * 00009 * Permission is hereby granted, free of charge, to any person obtaining a copy 00010 * of this software and associated documentation files (the "Software"), to deal 00011 * in the Software without restriction, including without limitation the rights 00012 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 * copies of the Software, and to permit persons to whom the Software is 00014 * furnished to do so, subject to the following conditions: 00015 * 00016 * The above copyright notice and this permission notice shall be included in 00017 * all copies or substantial portions of the Software. 00018 * 00019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 * THE SOFTWARE. 00026 */ 00027 00028 #import <Availability.h> 00029 00030 #import "Platforms/CCGL.h" 00031 #import "CCAction.h" 00032 #import "ccTypes.h" 00033 #import "CCTexture2D.h" 00034 #import "CCProtocols.h" 00035 #import "ccConfig.h" 00036 #import "Support/CCArray.h" 00037 00038 enum { 00039 kCCNodeTagInvalid = -1, 00040 }; 00041 00042 @class CCCamera; 00043 @class CCGridBase; 00044 00099 @interface CCNode : NSObject 00100 { 00101 // rotation angle 00102 float rotation_; 00103 00104 // scaling factors 00105 float scaleX_, scaleY_; 00106 00107 // position of the node 00108 CGPoint position_; 00109 CGPoint positionInPixels_; 00110 00111 // skew angles 00112 float skewX_, skewY_; 00113 00114 // is visible 00115 BOOL visible_; 00116 00117 // anchor point in pixels 00118 CGPoint anchorPointInPixels_; 00119 // anchor point normalized 00120 CGPoint anchorPoint_; 00121 // If YES the transformtions will be relative to (-transform.x, -transform.y). 00122 // Sprites, Labels and any other "small" object uses it. 00123 // Scenes, Layers and other "whole screen" object don't use it. 00124 BOOL isRelativeAnchorPoint_; 00125 00126 // untransformed size of the node 00127 CGSize contentSize_; 00128 CGSize contentSizeInPixels_; 00129 00130 // transform 00131 CGAffineTransform transform_, inverse_; 00132 #if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX 00133 GLfloat transformGL_[16]; 00134 #endif 00135 00136 // openGL real Z vertex 00137 float vertexZ_; 00138 00139 // a Camera 00140 CCCamera *camera_; 00141 00142 // a Grid 00143 CCGridBase *grid_; 00144 00145 // z-order value 00146 NSInteger zOrder_; 00147 00148 // array of children 00149 CCArray *children_; 00150 00151 // weakref to parent 00152 CCNode *parent_; 00153 00154 // a tag. any number you want to assign to the node 00155 NSInteger tag_; 00156 00157 // user data field 00158 void *userData_; 00159 00160 // Is running 00161 BOOL isRunning_; 00162 00163 // To reduce memory, place BOOLs that are not properties here: 00164 BOOL isTransformDirty_:1; 00165 BOOL isInverseDirty_:1; 00166 #if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX 00167 BOOL isTransformGLDirty_:1; 00168 #endif 00169 } 00170 00172 @property(nonatomic,readonly) NSInteger zOrder; 00181 @property (nonatomic,readwrite) float vertexZ; 00182 00188 @property(nonatomic,readwrite,assign) float skewX; 00189 00195 @property(nonatomic,readwrite,assign) float skewY; 00197 @property(nonatomic,readwrite,assign) float rotation; 00199 @property(nonatomic,readwrite,assign) float scale; 00201 @property(nonatomic,readwrite,assign) float scaleX; 00203 @property(nonatomic,readwrite,assign) float scaleY; 00205 @property(nonatomic,readwrite,assign) CGPoint position; 00207 @property(nonatomic,readwrite,assign) CGPoint positionInPixels; 00210 @property(nonatomic,readonly) CCCamera* camera; 00212 @property(nonatomic,readonly) CCArray *children; 00214 @property(nonatomic,readwrite,retain) CCGridBase* grid; 00216 @property(nonatomic,readwrite,assign) BOOL visible; 00224 @property(nonatomic,readwrite) CGPoint anchorPoint; 00228 @property(nonatomic,readonly) CGPoint anchorPointInPixels; 00229 00235 @property (nonatomic,readwrite) CGSize contentSize; 00236 00242 @property (nonatomic,readwrite) CGSize contentSizeInPixels; 00243 00245 @property(nonatomic,readonly) BOOL isRunning; 00247 @property(nonatomic,readwrite,assign) CCNode* parent; 00252 @property(nonatomic,readwrite,assign) BOOL isRelativeAnchorPoint; 00254 @property(nonatomic,readwrite,assign) NSInteger tag; 00256 @property(nonatomic,readwrite,assign) void *userData; 00257 00258 // initializators 00262 +(id) node; 00264 -(id) init; 00265 00266 00267 // scene managment 00268 00273 -(void) onEnter; 00278 -(void) onEnterTransitionDidFinish; 00283 -(void) onExit; 00284 00285 00286 // composition: ADD 00287 00292 -(void) addChild: (CCNode*)node; 00293 00298 -(void) addChild: (CCNode*)node z:(NSInteger)z; 00299 00304 -(void) addChild: (CCNode*)node z:(NSInteger)z tag:(NSInteger)tag; 00305 00306 // composition: REMOVE 00307 00312 -(void) removeFromParentAndCleanup:(BOOL)cleanup; 00313 00317 -(void) removeChild: (CCNode*)node cleanup:(BOOL)cleanup; 00318 00322 -(void) removeChildByTag:(NSInteger) tag cleanup:(BOOL)cleanup; 00323 00327 -(void) removeAllChildrenWithCleanup:(BOOL)cleanup; 00328 00329 // composition: GET 00334 -(CCNode*) getChildByTag:(NSInteger) tag; 00335 00339 -(void) reorderChild:(CCNode*)child z:(NSInteger)zOrder; 00340 00344 -(void) cleanup; 00345 00346 // draw 00347 00359 -(void) draw; 00361 -(void) visit; 00362 00363 // transformations 00364 00366 -(void) transform; 00367 00373 -(void) transformAncestors; 00374 00381 - (CGRect) boundingBox; 00382 00389 - (CGRect) boundingBoxInPixels; 00390 00391 00392 // actions 00393 00400 -(CCAction*) runAction: (CCAction*) action; 00402 -(void) stopAllActions; 00404 -(void) stopAction: (CCAction*) action; 00408 -(void) stopActionByTag:(NSInteger) tag; 00413 -(CCAction*) getActionByTag:(NSInteger) tag; 00419 -(NSUInteger) numberOfRunningActions; 00420 00421 // timers 00422 00424 //-(BOOL) isScheduled: (SEL) selector; 00425 00432 -(void) scheduleUpdate; 00433 00440 -(void) scheduleUpdateWithPriority:(NSInteger)priority; 00441 00442 /* unschedules the "update" method. 00443 00444 @since v0.99.3 00445 */ 00446 -(void) unscheduleUpdate; 00447 00448 00452 -(void) schedule: (SEL) s; 00459 -(void) schedule: (SEL) s interval:(ccTime)seconds; 00461 -(void) unschedule: (SEL) s; 00462 00467 -(void) unscheduleAllSelectors; 00468 00472 -(void) resumeSchedulerAndActions; 00476 -(void) pauseSchedulerAndActions; 00477 00478 00479 // transformation methods 00480 00485 - (CGAffineTransform)nodeToParentTransform; 00490 - (CGAffineTransform)parentToNodeTransform; 00494 - (CGAffineTransform)nodeToWorldTransform; 00498 - (CGAffineTransform)worldToNodeTransform; 00502 - (CGPoint)convertToNodeSpace:(CGPoint)worldPoint; 00506 - (CGPoint)convertToWorldSpace:(CGPoint)nodePoint; 00511 - (CGPoint)convertToNodeSpaceAR:(CGPoint)worldPoint; 00516 - (CGPoint)convertToWorldSpaceAR:(CGPoint)nodePoint; 00517 00518 #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 00519 00522 - (CGPoint)convertTouchToNodeSpace:(UITouch *)touch; 00527 - (CGPoint)convertTouchToNodeSpaceAR:(UITouch *)touch; 00528 #endif // __IPHONE_OS_VERSION_MAX_ALLOWED 00529 @end