intangible intangible how to change background color with box2d tempalte
Posts 8
Added by intangible intangible over 1 year ago

How to change background color with box2d template in cocos2d-x?
I use Chapter 2 tutorial method , but the background is not change.
I'm not only use box2d, but also change the scene's background color.
So I choose project is cocos2d-x + box2d.

I had tried not in cocos2d-x+box2d template , chapter 2 tutorial method is OK.
But use cocos2d-x+box2d can't execute.

Who can teach me,thank you~

Zhe Wang RE: how to change background color with box2d tempalte
Posts 1642
Location Amoy, China
Added by Zhe Wang over 1 year ago

Have you changed the main layer's parent class from CCLayer to CCLayerColor, then initialized it with a different color?

Enjoy Coding, Enjoy Life.

intangible intangible RE: how to change background color with box2d tempalte
Posts 8
Added by intangible intangible over 1 year ago

First, I appreciate you take the time to help me.
in my HelloWorldScene.h I have change my class from CCLayer to CCLayerColor.
----
class HelloWorld : public cocos2d::CCLayerColor
----
then i had added code in HelloWorldScene.cpp.
--------
HelloWorld::HelloWorld() {
setIsTouchEnabled( true );
setIsAccelerometerEnabled( true );
if(!CCLayerColor::initWithColor( ccc4(255,255,255,255) ));
....
--------------------

but the background have not changed.The color is still black.

it is cocos2d-x + box2d template.
thank you very much.

Tevfik Aloglu RE: how to change background color with box2d tempalte
Posts 16
Added by Tevfik Aloglu 4 months ago

I have exactly same problem.. I use cocos2d-x ;
i did exactly

1. In HelloWorldScene.h
class HelloWorld : public CCLayerColor

2. In HelloWorldScene.cpp
bool HelloWorld::init() {
if (CCLayerColor::initWithColor( ccc4(0,0,255,255) )
// ...
}

it doesnt change anything i tried with different opacity and different rgb values?
why can it be?

Lance Gray RE: how to change background color with box2d tempalte
Posts 397
Location Coffee World
Added by Lance Gray 4 months ago

You have to call this -> setColor( ccc4( R, G, B, O ) ); on the init() method.

Check out my blog: sudo make_me_a_game

Tevfik Aloglu RE: how to change background color with box2d tempalte
Posts 16
Added by Tevfik Aloglu 4 months ago

Lance Gray wrote:

You have to call this -> setColor( ccc4( R, G, B, O ) ); on the init() method.

Thanks for answer but first of all setColor takes a different parameter.
virtual void setColor(const ccColor3B & var)

Second, when i try this->getColor(), i see that R,G,B is changed but just screen color did not


(1-5/5)