[Cocos2d-x 2.2.2] Change background color

I’m developing a multi resolution game. I would like to keep the aspect ratio in all devices, so I decided to use kResolutionShowAll:

CCSize screenSize = pEGLView->getFrameSize(); CCSize designSize = CCSize(320, 480); CCEGLView::sharedOpenGLView()->setDesignResolutionSize (designSize.width, designSize.height, kResolutionShowAll);

I tried my game on iPad and it’s fine, it keeps the aspect ratio the game was designed for (1.5). Cocos fills the left and right border with a black block. Unafortunatelly, my game scene’s background are white.

Anybody knows a way to change the background’s color of the entire app?

I tried to change the color in the EAGLView:

EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] pixelFormat: kEAGLColorFormatRGB565 depthFormat: GL_DEPTH24_STENCIL8_OES preserveBackbuffer: NO sharegroup: nil multiSampling: NO numberOfSamples: 0]; [__glView setBackgroundColor:[UIColor whiteColor]];

But this doesn’t work. Any help will be appreciated!

In CCDirector::setGLDefaultValues, there should be a line like that :
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
That one is for black (the default)

Change it to the color you want. For white, use :
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

It worked, thank you very much :slight_smile:

Is it possible to use a bitmap texture instead of black borders?

1 Like