From 9d85221c8cf1f0845668d570853eaa29946612b6 Mon Sep 17 00:00:00 2001 From: Panajev Date: Thu, 16 Aug 2012 12:53:24 +0200 Subject: [PATCH 1/4] (+): added support for scene popping and pushing with transitions. It only supports transitions responding to this message: +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s --- cocos2d/CCDirector.h | 14 ++++++++++++++ cocos2d/CCDirector.m | 36 ++++++++++++++++++++++++++++++++++++ tests/ActionsTest.m | 4 ++-- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/cocos2d/CCDirector.h b/cocos2d/CCDirector.h index 087ce1717c7..91708b027b2 100644 --- a/cocos2d/CCDirector.h +++ b/cocos2d/CCDirector.h @@ -255,6 +255,13 @@ and when to execute the Scenes. */ - (void) pushScene:(CCScene*) scene; +/**Suspends the execution of the running scene, pushing it on the stack of suspended scenes. + * The new scene will be executed and is going to be presented using a scene transition effect. + * Try to avoid big stacks of pushed scenes to reduce memory allocation. + * ONLY call it if there is a running scene. + */ +-(void) pushScene:(CCScene*) scene withTransition:(NSString*)transitionName duration:(ccTime)t; + /**Pops out a scene from the queue. * This scene will replace the running one. * The running scene will be deleted. If there are no more scenes in the stack the execution is terminated. @@ -262,6 +269,13 @@ and when to execute the Scenes. */ - (void) popScene; +/**Pops out a scene from the queue. + * This scene will replace the running one using a scene transition effect. + * The running scene will be deleted. If there are no more scenes in the stack the execution is terminated. + * ONLY call it if there is a running scene. + */ +-(void) popSceneWithTransition:(NSString*)transitionName duration:(ccTime)t; + /**Pops out all scenes from the queue until the root scene in the queue. * This scene will replace the running one. * The running scene will be deleted. If there are no more scenes in the stack the execution is terminated. diff --git a/cocos2d/CCDirector.m b/cocos2d/CCDirector.m index 3e3e253dcd4..3d08f8bf3b0 100644 --- a/cocos2d/CCDirector.m +++ b/cocos2d/CCDirector.m @@ -393,6 +393,22 @@ - (void) pushScene: (CCScene*) scene nextScene_ = scene; // nextScene_ is a weak ref } +-(void) pushScene:(CCScene*) scene withTransition: (NSString*)transitionName duration:(ccTime)t { + + NSAssert( scene != nil, @"Argument must be non-nil"); + + Class transitionClass = NSClassFromString(transitionName); + BOOL classTest = [transitionClass respondsToSelector:@selector(transitionWithDuration:scene:)]; + NSString * errorMsg = [NSString stringWithFormat:@"The transition \"%@\" is not a valid transition.", transitionName]; + NSAssert (classTest, errorMsg); + + sendCleanupToScene_ = NO; + + CCScene* newScene = [transitionClass transitionWithDuration:t scene:scene]; + [scenesStack_ addObject: newScene]; + nextScene_ = newScene; // nextScene_ is a weak ref +} + -(void) popScene { NSAssert( runningScene_ != nil, @"A running Scene is needed"); @@ -431,6 +447,26 @@ -(void) popToRootScene } } +-(void) popSceneWithTransition:(NSString*)transitionName duration:(ccTime)t +{ + NSAssert( runningScene_ != nil, @"A running Scene is needed"); + + Class transitionClass = NSClassFromString(transitionName); + BOOL classTest = [transitionClass respondsToSelector:@selector(transitionWithDuration:scene:)]; + NSString * errorMsg = [NSString stringWithFormat:@"The transition \"%@\" is not a valid transition.", transitionName]; + NSAssert (classTest, errorMsg); + + [scenesStack_ removeLastObject]; + NSUInteger c = [scenesStack_ count]; + if( c == 0 ) { + [self end]; + } else { + CCScene* scene = [transitionClass transitionWithDuration:t scene:[scenesStack_ objectAtIndex:c-1]]; + [scenesStack_ replaceObjectAtIndex:c-1 withObject:scene]; + nextScene_ = scene; + } +} + -(void) end { [runningScene_ onExit]; diff --git a/tests/ActionsTest.m b/tests/ActionsTest.m index 67f8966cd4b..7f1a033dab2 100644 --- a/tests/ActionsTest.m +++ b/tests/ActionsTest.m @@ -157,14 +157,14 @@ -(void) nextCallback: (id) sender { CCScene *s = [CCScene node]; [s addChild: [nextAction() node]]; - [[CCDirector sharedDirector] replaceScene: s]; + [[CCDirector sharedDirector] pushScene:s withTransition:@"CCTransitionMoveInR" duration:1.0f]; } -(void) backCallback: (id) sender { CCScene *s = [CCScene node]; [s addChild: [backAction() node]]; - [[CCDirector sharedDirector] replaceScene: s]; + [[CCDirector sharedDirector] popSceneWithTransition:@"CCTransitionMoveInL" duration:1.0f]; } From c3d88b21657b82f4dd6b693894505b4d98aab4eb Mon Sep 17 00:00:00 2001 From: Panajev Date: Thu, 16 Aug 2012 13:38:42 +0200 Subject: [PATCH 2/4] (+): added support for more types of transitions and refactored the orientation related transition methods to bring them more in line with the colour based fading methods. Added new CCTransitionOrientationType.h header to allow this enum to be used in the Director without importing the whole CCTransition.h header. --- cocos2d-ios.xcodeproj/project.pbxproj | 2 + cocos2d/CCDirector.h | 35 +++++++- cocos2d/CCDirector.m | 117 +++++++++++++++++++++----- cocos2d/CCTransition.h | 19 +---- cocos2d/CCTransition.m | 6 +- cocos2d/CCTransitionOrientationType.h | 22 +++++ tests/ActionsTest.m | 4 +- tests/TransitionsTest.m | 24 +++--- 8 files changed, 176 insertions(+), 53 deletions(-) create mode 100644 cocos2d/CCTransitionOrientationType.h diff --git a/cocos2d-ios.xcodeproj/project.pbxproj b/cocos2d-ios.xcodeproj/project.pbxproj index 3edf13e30a7..80614e2533e 100644 --- a/cocos2d-ios.xcodeproj/project.pbxproj +++ b/cocos2d-ios.xcodeproj/project.pbxproj @@ -4768,6 +4768,7 @@ E0FDACE5123DAC8300F25BB4 /* larabie-16-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "larabie-16-hd.png"; sourceTree = ""; }; E0FDACE6123DAC8300F25BB4 /* larabie-16.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "larabie-16.png"; sourceTree = ""; }; E0FDACED123DAD0000F25BB4 /* tuffy_bold_italic-charmap-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tuffy_bold_italic-charmap-hd.png"; sourceTree = ""; }; + E610367B15DD0C4F00819640 /* CCTransitionOrientationType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCTransitionOrientationType.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -6240,6 +6241,7 @@ E0112F50120CB406006667F8 /* CCTransitionPageTurn.m */, A0C3814F14BA0548001655CC /* CCTransitionProgress.h */, A0C3815014BA0548001655CC /* CCTransitionProgress.m */, + E610367B15DD0C4F00819640 /* CCTransitionOrientationType.h */, ); name = "Layers, Scenes, Transitions Nodes"; sourceTree = ""; diff --git a/cocos2d/CCDirector.h b/cocos2d/CCDirector.h index 91708b027b2..332bf07a4dc 100644 --- a/cocos2d/CCDirector.h +++ b/cocos2d/CCDirector.h @@ -27,11 +27,12 @@ #import "ccConfig.h" #import "ccTypes.h" #import "ccMacros.h" - #import "CCProtocols.h" #import "Platforms/CCGL.h" #import "kazmath/mat4.h" +#import "CCTransitionOrientationType.h" + /** @typedef ccDirectorProjection Possible OpenGL projections used by director */ @@ -262,6 +263,22 @@ and when to execute the Scenes. */ -(void) pushScene:(CCScene*) scene withTransition:(NSString*)transitionName duration:(ccTime)t; +/**Suspends the execution of the running scene, pushing it on the stack of suspended scenes. + * The new scene will be executed and is going to be presented using a scene transition effect. + * Try to avoid big stacks of pushed scenes to reduce memory allocation. + * ONLY call it if there is a running scene. + */ +-(void) pushScene:(CCScene*) scene withTransition:(NSString*)transitionName duration:(ccTime)t + withColor:(ccColor3B)color; + +/**Suspends the execution of the running scene, pushing it on the stack of suspended scenes. + * The new scene will be executed and is going to be presented using a scene transition effect. + * Try to avoid big stacks of pushed scenes to reduce memory allocation. + * ONLY call it if there is a running scene. + */ +-(void) pushScene:(CCScene*) scene withTransition:(NSString*)transitionName duration:(ccTime)t + withOrientation:(tOrientation)orientation; + /**Pops out a scene from the queue. * This scene will replace the running one. * The running scene will be deleted. If there are no more scenes in the stack the execution is terminated. @@ -276,6 +293,22 @@ and when to execute the Scenes. */ -(void) popSceneWithTransition:(NSString*)transitionName duration:(ccTime)t; +/**Pops out a scene from the queue. + * This scene will replace the running one using a scene transition effect. + * The running scene will be deleted. If there are no more scenes in the stack the execution is terminated. + * ONLY call it if there is a running scene. + */ +-(void) popSceneWithTransition:(NSString*)transitionName duration:(ccTime)t + withColor:(ccColor3B)color; + +/**Pops out a scene from the queue. + * This scene will replace the running one using a scene transition effect. + * The running scene will be deleted. If there are no more scenes in the stack the execution is terminated. + * ONLY call it if there is a running scene. + */ +-(void) popSceneWithTransition:(NSString*)transitionName duration:(ccTime)t + withOrientation:(tOrientation)orientation; + /**Pops out all scenes from the queue until the root scene in the queue. * This scene will replace the running one. * The running scene will be deleted. If there are no more scenes in the stack the execution is terminated. diff --git a/cocos2d/CCDirector.m b/cocos2d/CCDirector.m index 3d08f8bf3b0..480cf7b5e48 100644 --- a/cocos2d/CCDirector.m +++ b/cocos2d/CCDirector.m @@ -409,6 +409,41 @@ -(void) pushScene:(CCScene*) scene withTransition: (NSString*)transitionName dur nextScene_ = newScene; // nextScene_ is a weak ref } +-(void) pushScene:(CCScene*) scene withTransition:(NSString*)transitionName duration:(ccTime)t + withColor:(ccColor3B)color +{ + NSAssert( scene != nil, @"Argument must be non-nil"); + + Class transitionClass = NSClassFromString(transitionName); + BOOL classTest = [transitionClass respondsToSelector:@selector(transitionWithDuration:scene:withColor:)]; + NSString * errorMsg = [NSString stringWithFormat:@"The transition \"%@\" is not a valid transition.", transitionName]; + NSAssert (classTest, errorMsg); + + sendCleanupToScene_ = NO; + + CCScene* newScene = [transitionClass transitionWithDuration:t scene:scene withColor:color]; + [scenesStack_ addObject: newScene]; + nextScene_ = newScene; // nextScene_ is a weak ref +} + +-(void) pushScene:(CCScene*) scene withTransition:(NSString*)transitionName duration:(ccTime)t + withOrientation:(tOrientation)orientation +{ + NSAssert( scene != nil, @"Argument must be non-nil"); + + Class transitionClass = NSClassFromString(transitionName); + BOOL classTest = [transitionClass respondsToSelector:@selector(transitionWithDuration:scene:withOrientation:)]; + NSString * errorMsg = [NSString stringWithFormat:@"The transition \"%@\" is not a valid transition.", transitionName]; + NSAssert (classTest, errorMsg); + + sendCleanupToScene_ = NO; + + CCScene* newScene = [transitionClass transitionWithDuration:t scene:scene withOrientation:orientation]; + [scenesStack_ addObject: newScene]; + nextScene_ = newScene; // nextScene_ is a weak ref + +} + -(void) popScene { NSAssert( runningScene_ != nil, @"A running Scene is needed"); @@ -424,6 +459,68 @@ -(void) popScene } } +-(void) popSceneWithTransition:(NSString*)transitionName duration:(ccTime)t +{ + NSAssert( runningScene_ != nil, @"A running Scene is needed"); + + Class transitionClass = NSClassFromString(transitionName); + BOOL classTest = [transitionClass respondsToSelector:@selector(transitionWithDuration:scene:)]; + NSString * errorMsg = [NSString stringWithFormat:@"The transition \"%@\" is not a valid transition.", transitionName]; + NSAssert (classTest, errorMsg); + + [scenesStack_ removeLastObject]; + NSUInteger c = [scenesStack_ count]; + if( c == 0 ) { + [self end]; + } else { + CCScene* scene = [transitionClass transitionWithDuration:t scene:[scenesStack_ objectAtIndex:c-1]]; + [scenesStack_ replaceObjectAtIndex:c-1 withObject:scene]; + nextScene_ = scene; + } +} + +-(void) popSceneWithTransition:(NSString*)transitionName duration:(ccTime)t + withColor:(ccColor3B)color +{ + NSAssert( runningScene_ != nil, @"A running Scene is needed"); + + Class transitionClass = NSClassFromString(transitionName); + BOOL classTest = [transitionClass respondsToSelector:@selector(transitionWithDuration:scene:withColor:)]; + NSString * errorMsg = [NSString stringWithFormat:@"The transition \"%@\" is not a valid transition.", transitionName]; + NSAssert (classTest, errorMsg); + + [scenesStack_ removeLastObject]; + NSUInteger c = [scenesStack_ count]; + if( c == 0 ) { + [self end]; + } else { + CCScene* scene = [transitionClass transitionWithDuration:t scene:[scenesStack_ objectAtIndex:c-1] withColor:color]; + [scenesStack_ replaceObjectAtIndex:c-1 withObject:scene]; + nextScene_ = scene; + } +} + +-(void) popSceneWithTransition:(NSString*)transitionName duration:(ccTime)t + withOrientation:(tOrientation)orientation +{ + NSAssert( runningScene_ != nil, @"A running Scene is needed"); + + Class transitionClass = NSClassFromString(transitionName); + BOOL classTest = [transitionClass respondsToSelector:@selector(transitionWithDuration:scene:withOrientation:)]; + NSString * errorMsg = [NSString stringWithFormat:@"The transition \"%@\" is not a valid transition.", transitionName]; + NSAssert (classTest, errorMsg); + + [scenesStack_ removeLastObject]; + NSUInteger c = [scenesStack_ count]; + if( c == 0 ) { + [self end]; + } else { + CCScene* scene = [transitionClass transitionWithDuration:t scene:[scenesStack_ objectAtIndex:c-1] withOrientation:orientation]; + [scenesStack_ replaceObjectAtIndex:c-1 withObject:scene]; + nextScene_ = scene; + } +} + -(void) popToRootScene { NSAssert(runningScene_ != nil, @"A running Scene is needed"); @@ -447,26 +544,6 @@ -(void) popToRootScene } } --(void) popSceneWithTransition:(NSString*)transitionName duration:(ccTime)t -{ - NSAssert( runningScene_ != nil, @"A running Scene is needed"); - - Class transitionClass = NSClassFromString(transitionName); - BOOL classTest = [transitionClass respondsToSelector:@selector(transitionWithDuration:scene:)]; - NSString * errorMsg = [NSString stringWithFormat:@"The transition \"%@\" is not a valid transition.", transitionName]; - NSAssert (classTest, errorMsg); - - [scenesStack_ removeLastObject]; - NSUInteger c = [scenesStack_ count]; - if( c == 0 ) { - [self end]; - } else { - CCScene* scene = [transitionClass transitionWithDuration:t scene:[scenesStack_ objectAtIndex:c-1]]; - [scenesStack_ replaceObjectAtIndex:c-1 withObject:scene]; - nextScene_ = scene; - } -} - -(void) end { [runningScene_ onExit]; diff --git a/cocos2d/CCTransition.h b/cocos2d/CCTransition.h index f57a9490af2..36b912988f0 100644 --- a/cocos2d/CCTransition.h +++ b/cocos2d/CCTransition.h @@ -26,6 +26,8 @@ #import "CCScene.h" +#import "CCTransitionOrientationType.h" + @class CCActionInterval; @class CCNode; @@ -39,19 +41,6 @@ -(CCActionInterval*) easeActionWithAction:(CCActionInterval*)action; @end -/** Orientation Type used by some transitions - */ -typedef enum { - /// An horizontal orientation where the Left is nearer - kOrientationLeftOver = 0, - /// An horizontal orientation where the Right is nearer - kOrientationRightOver = 1, - /// A vertical orientation where the Up is nearer - kOrientationUpOver = 0, - /// A vertical orientation where the Bottom is nearer - kOrientationDownOver = 1, -} tOrientation; - /** Base class for CCTransition scenes */ @interface CCTransitionScene : CCScene @@ -80,9 +69,9 @@ typedef enum { tOrientation orientation; } /** creates a base transition with duration and incoming scene */ -+(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s orientation:(tOrientation)o; ++(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s withOrientation:(tOrientation)o; /** initializes a transition with duration and incoming scene */ --(id) initWithDuration:(ccTime) t scene:(CCScene*)s orientation:(tOrientation)o; +-(id) initWithDuration:(ccTime) t scene:(CCScene*)s withOrientation:(tOrientation)o; @end diff --git a/cocos2d/CCTransition.m b/cocos2d/CCTransition.m index f360a297ad3..1b1abdf5ac0 100644 --- a/cocos2d/CCTransition.m +++ b/cocos2d/CCTransition.m @@ -198,12 +198,12 @@ -(void) dealloc // Oriented Transition // @implementation CCTransitionSceneOriented -+(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s orientation:(tOrientation)o ++(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s withOrientation:(tOrientation)o { - return [[[self alloc] initWithDuration:t scene:s orientation:o] autorelease]; + return [[[self alloc] initWithDuration:t scene:s withOrientation:o] autorelease]; } --(id) initWithDuration:(ccTime) t scene:(CCScene*)s orientation:(tOrientation)o +-(id) initWithDuration:(ccTime) t scene:(CCScene*)s withOrientation:(tOrientation)o { if( (self=[super initWithDuration:t scene:s]) ) orientation = o; diff --git a/cocos2d/CCTransitionOrientationType.h b/cocos2d/CCTransitionOrientationType.h new file mode 100644 index 00000000000..4d7167f2426 --- /dev/null +++ b/cocos2d/CCTransitionOrientationType.h @@ -0,0 +1,22 @@ +// +// ccTransitionOrientationType.h +// cocos2d-ios +// +// Created by Goffredo Marocchi on 8/16/12. +// +// + +#import + +/** Orientation Type used by some transitions + */ +typedef enum { + /// An horizontal orientation where the Left is nearer + kOrientationLeftOver = 0, + /// An horizontal orientation where the Right is nearer + kOrientationRightOver = 1, + /// A vertical orientation where the Up is nearer + kOrientationUpOver = 0, + /// A vertical orientation where the Bottom is nearer + kOrientationDownOver = 1, +} tOrientation; diff --git a/tests/ActionsTest.m b/tests/ActionsTest.m index 7f1a033dab2..6682ce16b02 100644 --- a/tests/ActionsTest.m +++ b/tests/ActionsTest.m @@ -157,14 +157,14 @@ -(void) nextCallback: (id) sender { CCScene *s = [CCScene node]; [s addChild: [nextAction() node]]; - [[CCDirector sharedDirector] pushScene:s withTransition:@"CCTransitionMoveInR" duration:1.0f]; + [[CCDirector sharedDirector] pushScene:s withTransition:@"CCTransitionFlipX" duration:1.0f withOrientation:kOrientationUpOver]; } -(void) backCallback: (id) sender { CCScene *s = [CCScene node]; [s addChild: [backAction() node]]; - [[CCDirector sharedDirector] popSceneWithTransition:@"CCTransitionMoveInL" duration:1.0f]; + [[CCDirector sharedDirector] popSceneWithTransition:@"CCTransitionFade" duration:1.0f withColor:ccBLUE]; } diff --git a/tests/TransitionsTest.m b/tests/TransitionsTest.m index 576760137db..88aad8a4c8f 100644 --- a/tests/TransitionsTest.m +++ b/tests/TransitionsTest.m @@ -59,7 +59,7 @@ +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s; @implementation FlipXLeftOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationLeftOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationLeftOver]; } @end @implementation FadeWhiteTransition @@ -70,57 +70,57 @@ +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { @implementation FlipXRightOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationRightOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationRightOver]; } @end @implementation FlipYUpOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationUpOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationUpOver]; } @end @implementation FlipYDownOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationDownOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationDownOver]; } @end @implementation FlipAngularLeftOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationLeftOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationLeftOver]; } @end @implementation FlipAngularRightOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationRightOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationRightOver]; } @end @implementation ZoomFlipXLeftOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationLeftOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationLeftOver]; } @end @implementation ZoomFlipXRightOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationRightOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationRightOver]; } @end @implementation ZoomFlipYUpOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationUpOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationUpOver]; } @end @implementation ZoomFlipYDownOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationDownOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationDownOver]; } @end @implementation ZoomFlipAngularLeftOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationLeftOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationLeftOver]; } @end @implementation ZoomFlipAngularRightOver +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s { - return [self transitionWithDuration:t scene:s orientation:kOrientationRightOver]; + return [self transitionWithDuration:t scene:s withOrientation:kOrientationRightOver]; } @end From 37cad1767a141e0c7d94c40873d3a3542da072e3 Mon Sep 17 00:00:00 2001 From: Panajev Date: Thu, 16 Aug 2012 13:42:32 +0200 Subject: [PATCH 3/4] (x): small change to a comment block. --- cocos2d/CCTransitionOrientationType.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/CCTransitionOrientationType.h b/cocos2d/CCTransitionOrientationType.h index 4d7167f2426..00ae8105da8 100644 --- a/cocos2d/CCTransitionOrientationType.h +++ b/cocos2d/CCTransitionOrientationType.h @@ -1,5 +1,5 @@ // -// ccTransitionOrientationType.h +// CCTransitionOrientationType.h // cocos2d-ios // // Created by Goffredo Marocchi on 8/16/12. From 8fdaa0fc88aaa3cd2adae9707240213b43883ef1 Mon Sep 17 00:00:00 2001 From: Panajev Date: Tue, 11 Sep 2012 17:27:07 +0200 Subject: [PATCH 4/4] (+): added public property to allow a CCSprite subclass to forcefully disable debug drawing. --- cocos2d/CCSprite.h | 4 ++++ cocos2d/CCSprite.m | 57 ++++++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/cocos2d/CCSprite.h b/cocos2d/CCSprite.h index 497ce22b5c4..a6e36d030c1 100644 --- a/cocos2d/CCSprite.h +++ b/cocos2d/CCSprite.h @@ -107,6 +107,8 @@ // image is flipped BOOL flipX_; BOOL flipY_; + + BOOL forceDisableDebugDraw_; } /** whether or not the Sprite needs to be updated in the Atlas */ @@ -150,6 +152,8 @@ /** conforms to CCTextureProtocol protocol */ @property (nonatomic,readwrite) ccBlendFunc blendFunc; +@property (nonatomic, readwrite) BOOL forceDisableDebugDraw; + #pragma mark CCSprite - Initializers /** Creates an sprite with a texture. diff --git a/cocos2d/CCSprite.m b/cocos2d/CCSprite.m index 67478d86d58..6549f2060fc 100644 --- a/cocos2d/CCSprite.m +++ b/cocos2d/CCSprite.m @@ -71,6 +71,7 @@ @implementation CCSprite @synthesize blendFunc = blendFunc_; @synthesize textureAtlas = textureAtlas_; @synthesize offsetPosition = offsetPosition_; +@synthesize forceDisableDebugDraw = forceDisableDebugDraw_; +(id)spriteWithTexture:(CCTexture2D*)texture @@ -479,14 +480,16 @@ -(void)updateTransform [children_ makeObjectsPerformSelector:@selector(updateTransform)]; #if CC_SPRITE_DEBUG_DRAW - // draw bounding box - CGPoint vertices[4] = { - ccp( quad_.bl.vertices.x, quad_.bl.vertices.y ), - ccp( quad_.br.vertices.x, quad_.br.vertices.y ), - ccp( quad_.tr.vertices.x, quad_.tr.vertices.y ), - ccp( quad_.tl.vertices.x, quad_.tl.vertices.y ), - }; - ccDrawPoly(vertices, 4, YES); + if(!forceDisableDebugDraw_) { + // draw bounding box + CGPoint vertices[4] = { + ccp( quad_.bl.vertices.x, quad_.bl.vertices.y ), + ccp( quad_.br.vertices.x, quad_.br.vertices.y ), + ccp( quad_.tr.vertices.x, quad_.tr.vertices.y ), + ccp( quad_.tl.vertices.x, quad_.tl.vertices.y ), + }; + ccDrawPoly(vertices, 4, YES); + } #endif // CC_SPRITE_DEBUG_DRAW } @@ -533,23 +536,27 @@ -(void) draw #if CC_SPRITE_DEBUG_DRAW == 1 - // draw bounding box - CGPoint vertices[4]={ - ccp(quad_.tl.vertices.x,quad_.tl.vertices.y), - ccp(quad_.bl.vertices.x,quad_.bl.vertices.y), - ccp(quad_.br.vertices.x,quad_.br.vertices.y), - ccp(quad_.tr.vertices.x,quad_.tr.vertices.y), - }; - ccDrawPoly(vertices, 4, YES); + if(!forceDisableDebugDraw_) { + // draw bounding box + CGPoint vertices[4]={ + ccp(quad_.tl.vertices.x,quad_.tl.vertices.y), + ccp(quad_.bl.vertices.x,quad_.bl.vertices.y), + ccp(quad_.br.vertices.x,quad_.br.vertices.y), + ccp(quad_.tr.vertices.x,quad_.tr.vertices.y), + }; + ccDrawPoly(vertices, 4, YES); + } #elif CC_SPRITE_DEBUG_DRAW == 2 - // draw texture box - CGSize s = self.textureRect.size; - CGPoint offsetPix = self.offsetPosition; - CGPoint vertices[4] = { - ccp(offsetPix.x,offsetPix.y), ccp(offsetPix.x+s.width,offsetPix.y), - ccp(offsetPix.x+s.width,offsetPix.y+s.height), ccp(offsetPix.x,offsetPix.y+s.height) - }; - ccDrawPoly(vertices, 4, YES); + if(!forceDisableDebugDraw_) { + // draw texture box + CGSize s = self.textureRect.size; + CGPoint offsetPix = self.offsetPosition; + CGPoint vertices[4] = { + ccp(offsetPix.x,offsetPix.y), ccp(offsetPix.x+s.width,offsetPix.y), + ccp(offsetPix.x+s.width,offsetPix.y+s.height), ccp(offsetPix.x,offsetPix.y+s.height) + }; + ccDrawPoly(vertices, 4, YES); + } #endif // CC_SPRITE_DEBUG_DRAW CC_INCREMENT_GL_DRAWS(1); @@ -906,7 +913,7 @@ -(CCSpriteFrame*) displayFrame return [CCSpriteFrame frameWithTexture:texture_ rectInPixels:CC_RECT_POINTS_TO_PIXELS(rect_) rotated:rectRotated_ - offset:unflippedOffsetPositionFromCenter_ + offset:CC_POINT_POINTS_TO_PIXELS(unflippedOffsetPositionFromCenter_) originalSize:CC_SIZE_POINTS_TO_PIXELS(contentSize_)]; }