Reputation: 2122
I am creating an iPhone application using both UIKit
and cocos2d
. Now, in one of my ViewControllers
, I am adding a HelloWorldLayer
as a subview. Which is successfully added.
Now this layer is being added with a black background color. I want its background color to be clearColor
, precisely, I want it to be transparant, so that I can view the contents in my ViewController except for the contents in the HelloWorldLayer
.
I know how to change the CCLayer
background color. I am using ccc4(r, g, b, a)
for it.
Here id my code:
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super's" return value
if( (self=[super initWithColor:ccc4(0, 0, 0, 128)]) ) {
CGSize windowSize = [[CCDirector sharedDirector] winSize];
CCSprite *imgRoof;
imgRoof = [CCSprite spriteWithFile:@"Tops.png"];
imgRoof.position = ccp(windowSize.width/2,windowSize.height/2);
[self addChild:imgRoof];
CCAction* action = [CCBlink actionWithDuration:20 blinks:20];
[imgRoof runAction:action];
}
return self;
}
I just want to know the color code for clearColor
for ccc4()
. Can any one help me please, I am really stuck.
Thanks a lot in advance!!!
Upvotes: 0
Views: 3188
Reputation: 2122
Finally I didn't find a proper answer to this question, after looking for many docs and searching for days in google, found no proper solution, and no color code is available for clearColor
for ccc4
so I used a patch for my application.
I am setting the the same image as a background CCSprite
to my HelloWorldLayer
, which I am using in the ViewController
as a background on which I m adding the HelloWorldLayer
scene, so that one don't see the black background, and even user presumes that the behind ViewController
is visible apart from the HelloWorldLayer
contents.
This is a solution particularly for my application. For other situations, I can't say. If anyone finds any solution to this, please let me know.
Thanks!!!
Upvotes: 0
Reputation: 348
Try this, it works for me.
UIColor *color = [UIColor clearColor];
CGColorRef layerBackgroundColor = [color CGColor];
[subLayer setBackgroundColor:layerBackgroundColor];
Upvotes: 0
Reputation: 4329
Try This...
CCLayer *pauseLayer;
CGSize size = [[CCDirector sharedDirector] winSize];
pauseLayer = [CCLayerColor layerWithColor: ccc4(0, 0, 0, 128) width: size.width height: size.height];
pauseLayer.position = CGPointZero;
[self addChild: pauseLayer];
E.X for using ccc4
layerWithColor:ccc4(Red, Green, Blue, Opacity)
The first three numbers are "RGB" colors and the last number is opacity. Each can have a value in range between 0 and 255.
Upvotes: 0
Reputation: 20021
yourView.layer.backgroundColor=[[UIColor clearColor]CGColor];
will do the job for you
Dont forgot
#import <QuartzCore/QuartzCore.h>
EDIT
CCLayerColor* colorLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 128)];
[self addChild:colorLayer z:0];
The first three numbers are "RGB" colors and the last number is opacity. Each can have a value in range between 0 and 255.
Upvotes: 2