Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to change the background of the scene in cocos2dx android
    primarykey
    data
    text
    <p>I have started Game Development using cocos2dx. And started with HelloWorld sample game. I am able to run this sample game. But when I try to change the Background Color, I am getting error in </p> <pre><code> **HelloWorldScene.h** The type 'HelloWorld' must implement the inherited pure virtual method 'cocos2d::CCRGBAProtocol::setOpacity' **Changes:** class HelloWorld : public cocos2d::CCLayerColor </code></pre> <p>and also in </p> <pre><code> **HelloWorldScene.cpp** Invalid arguments ' Candidates are: bool initWithColor(const cocos2d::_ccColor4B &amp;, ?, ?) bool initWithColor(const cocos2d::_ccColor4B &amp;) ' **Changes:** CC_BREAK_IF(!CCLayerColor::initWithColor(ccc4(255,255,255,255))); </code></pre> <p>I am new for cocos2dx and also for C++. Is there any thing left to include or what? Please help me to solve this issue. Thank You.</p> <p><strong>EDIT:</strong></p> <p><strong>HelloWorldScene.cpp</strong></p> <pre><code>#include "HelloWorldScene.h" using namespace cocos2d; using namespace CocosDenshion; CCScene* HelloWorld::scene() { CCScene * scene = NULL; do { // 'scene' is an autorelease object //CCScene *scene = CCScene::create(); scene = CCScene::create(); CC_BREAK_IF(!scene); // 'layer' is an autorelease object HelloWorld *layer = HelloWorld::create(); CC_BREAK_IF(!layer); // add layer as a child to scene scene-&gt;addChild(layer); } while (0); // return the scene return scene; } // on "init" you need to initialize your instance bool HelloWorld::init() { bool bRet = false; do { ////////////////////////////// // 1. super init first //if ( !CCLayer::init()) //{ //return false; //} //CC_BREAK_IF(!CCLayer::init()); CC_BREAK_IF(!CCLayerColor::initWithColor(ccc4(255,255,255,255))); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback) ); pCloseItem-&gt;setPosition( ccp(CCDirector::sharedDirector()-&gt;getWinSize().width - 20, 20) ); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu-&gt;setPosition( CCPointZero ); this-&gt;addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label CCLabelTTF* pLabel = CCLabelTTF::create("GAME", "Thonburi", 38); // ask director the window size CCSize size = CCDirector::sharedDirector()-&gt;getWinSize(); // position the label on the center of the screen pLabel-&gt;setPosition( ccp(size.width / 2, size.height - 20) ); // add the label as a child to this layer this-&gt;addChild(pLabel, 1); // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("Untitled1.png"); // position the sprite on the center of the screen pSprite-&gt;setPosition( ccp(size.width/2, size.height/2) ); // add the sprite as a child to this layer this-&gt;addChild(pSprite, 0); CCSprite* player = CCSprite::create("Player.png", CCRectMake(0, 0, 27, 50)); player-&gt;setPosition(ccp(player-&gt;getContentSize().width/2, size.height/2)); this-&gt;addChild(player); bRet = true; } while (0); return bRet; } void HelloWorld::menuCloseCallback(CCObject* pSender) { CCDirector::sharedDirector()-&gt;end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0); #endif } </code></pre> <p><strong>HelloWorldScene.h</strong></p> <pre><code>#ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" #include "SimpleAudioEngine.h" //class HelloWorld : public cocos2d::CCLayer class HelloWorld : public cocos2d::CCLayerColor { public: // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone virtual bool init(); // there's no 'id' in cpp, so we recommand to return the exactly class pointer static cocos2d::CCScene* scene(); // a selector callback void menuCloseCallback(CCObject* pSender); // implement the "static node()" method manually CREATE_FUNC(HelloWorld); }; #endif // __HELLOWORLD_SCENE_H__ </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload