Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added public property to allow a CCSprite subclass to forcefully disable debug drawing. #234

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cocos2d-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4768,6 +4768,7 @@
E0FDACE5123DAC8300F25BB4 /* larabie-16-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "larabie-16-hd.png"; sourceTree = "<group>"; };
E0FDACE6123DAC8300F25BB4 /* larabie-16.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "larabie-16.png"; sourceTree = "<group>"; };
E0FDACED123DAD0000F25BB4 /* tuffy_bold_italic-charmap-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tuffy_bold_italic-charmap-hd.png"; sourceTree = "<group>"; };
E610367B15DD0C4F00819640 /* CCTransitionOrientationType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCTransitionOrientationType.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -6240,6 +6241,7 @@
E0112F50120CB406006667F8 /* CCTransitionPageTurn.m */,
A0C3814F14BA0548001655CC /* CCTransitionProgress.h */,
A0C3815014BA0548001655CC /* CCTransitionProgress.m */,
E610367B15DD0C4F00819640 /* CCTransitionOrientationType.h */,
);
name = "Layers, Scenes, Transitions Nodes";
sourceTree = "<group>";
Expand Down
49 changes: 48 additions & 1 deletion cocos2d/CCDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -255,13 +256,59 @@ 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;

/**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.
* ONLY call it if there is a running scene.
*/
- (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 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.
Expand Down
113 changes: 113 additions & 0 deletions cocos2d/CCDirector.m
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,57 @@ - (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) 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");
Expand All @@ -408,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");
Expand Down
4 changes: 4 additions & 0 deletions cocos2d/CCSprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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.
Expand Down
57 changes: 32 additions & 25 deletions cocos2d/CCSprite.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ @implementation CCSprite
@synthesize blendFunc = blendFunc_;
@synthesize textureAtlas = textureAtlas_;
@synthesize offsetPosition = offsetPosition_;
@synthesize forceDisableDebugDraw = forceDisableDebugDraw_;


+(id)spriteWithTexture:(CCTexture2D*)texture
Expand Down Expand Up @@ -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

}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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_)];
}

Expand Down
19 changes: 4 additions & 15 deletions cocos2d/CCTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@


#import "CCScene.h"
#import "CCTransitionOrientationType.h"

@class CCActionInterval;
@class CCNode;

Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions cocos2d/CCTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading