How to use a UIView with a CCLayer cocs2d?

Forums Programming cocos2d support (graphics engine) How to use a UIView with a CCLayer cocs2d?

This topic contains 7 replies, has 3 voices, and was last updated by  MacSteve85 1 year, 5 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
Author Posts
Author Posts
November 9, 2012 at 10:50 pm #245233

MacSteve85
Participant
@macsteve85

I am playing a short video with CCVideoPlayer in cocos2d and at the end of it I am capturing the very last frame of the video and I am showing it on the screen using a UIVeiw because trying to draw it on a CCLayer makes the image show up with slightly different colors. I would imagine that is because the way that things are drawn in cocos2d is different than the way they are drawn on a UIView. So I need some way to keep the image on the screen Using the UIview, and I need to be able to draw sprites etc… on top of this view. So my question is, Is there a way to make a CCLayer transparent so that the UIView containing the image can still be seen and then draw on top of the image using a CCLayer?

November 10, 2012 at 3:01 am #391861

cocos
Participant
@cocos

You can play with opacity of the color layer (CCLayerColor):

[m_colorLayer setOpacity:o];

November 12, 2012 at 6:50 pm #391862

MacSteve85
Participant
@macsteve85

I have tried that but the background just goes black and the UIView will not show through.

November 12, 2012 at 7:07 pm #391863

slycrel
Participant
@slycrel

I had to do something similar in the past and documented it here:

http://stackoverflow.com/questions/4454758/cocos2d-playing-a-video-in-the-background-of-a-menu/4479700#4479700

I’m not sure if that exact thing will work with the current version of cocos2d, but it might point you in the right direction.

November 12, 2012 at 7:09 pm #391864

cocos
Participant
@cocos

You have to init CCLayerColor layer properly. You can have a transparent layer.

November 12, 2012 at 8:36 pm #391865

MacSteve85
Participant
@macsteve85

@cocos how do you mean by init the CCLayerColor Layer Properly?

November 12, 2012 at 8:50 pm #391866

cocos
Participant
@cocos

How do you initialize your layer? You should be able to control colors and opacity.

E.g:

@interface CCGameLayer :  CCLayerColor
{
//...
}

@implementation CCGameLayer

- (id) initWithColor:(ccColor4B)color width: (GLfloat)w height:(GLfloat)h
{
if( (self=[super initWithColor:color width:w height:h]) )
{
//...
}
return self;
}
//...

November 12, 2012 at 10:08 pm #391867

MacSteve85
Participant
@macsteve85

@slycrel Thanks so much for the help that was exactly what I was looking for.

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

You must be logged in to reply to this topic.