Transparent UIView on top of cocos2d layer

Forums Programming cocos2d support (graphics engine) Transparent UIView on top of cocos2d layer

This topic contains 6 replies, has 4 voices, and was last updated by  wasimu 3 years, 8 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
Author Posts
Author Posts
July 25, 2010 at 5:09 pm #223492



I have just upgraded from a really older version of cocos2d (0.8.2) to the current latest, and I am facing a transparency problem with an UIView.

It was working fine with the older version. I load an image in a UIView, then put into a ScrollView and then add it has an openGL subview. Now the content of the UIView (a transparent PNG) appears with a black background.

Here is the code, any idea is welcome…

UIView *block = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, instheight)];

block.backgroundColor = [UIColor clearColor];

block.backgroundColor = UIColor alloc] initWithPatternImage:[UIImage imageNamed:[CMR_Game getResourcesFile:@"long_instructions.png"];

block.opaque = NO;

UIScrollView *sview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 180,320, 220)];

sview.autoresizesSubviews = YES;

sview.delegate = self;

sview.userInteractionEnabled = YES;

sview.minimumZoomScale = 0.25;

sview.maximumZoomScale = 2;

sview.scrollEnabled =YES;

sview.bounces = NO;

sview.bouncesZoom = YES;

sview.contentSize = CGSizeMake(320, instheight);

sview.contentOffset = CGPointZero;

sview.scrollsToTop = YES;

[sview addSubview:block];

[sview setTag:1];

[[[CCDirector sharedDirector] openGLView] addSubview:sview];

Many thanks for your help !

July 26, 2010 at 8:58 am #291770


Anybody ?

July 26, 2010 at 10:04 am #291771


No idea… although the EAGLView changed a little bit in v0.99.4, it behaves basically like in v0.8.2. Could you try with v0.99.3 ?

PS: Don’t forget to post code between backticks (`).

July 26, 2010 at 12:29 pm #291772


Sorry I forgot for backticks…

I have just tried with v0.99.3, it makes no difference.

Any other idea or clue is more than welcome :)

July 26, 2010 at 4:06 pm #291773


It seems to be a blending problem, although I don’t think UIView/CALayer have a settable blend function. You could try initWithWhite:alpha: to see if the problem is related to your image or not.

July 29, 2010 at 1:22 pm #291774


Thanks guys for suggestions. Since I didn’t find a way to make it work, I have finally used the cocos2d ScrollView implementation found here :

August 8, 2010 at 5:40 am #291775


Got it just add

[block setAlpha:0.3];


block.opaque = NO;

This seems to sets the blending

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.