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
**HelloWorldScene.h**
The type 'HelloWorld' must implement the inherited pure virtual method 'cocos2d::CCRGBAProtocol::setOpacity'
**Changes:**
class HelloWorld : public cocos2d::CCLayerColor
and also in
**HelloWorldScene.cpp**
Invalid arguments '
Candidates are:
bool initWithColor(const cocos2d::_ccColor4B &, ?, ?)
bool initWithColor(const cocos2d::_ccColor4B &)
'
**Changes:**
CC_BREAK_IF(!CCLayerColor::initWithColor(ccc4(255,255,255,255)));
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.
EDIT:
HelloWorldScene.cpp
#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->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->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
this->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()->getWinSize();
// position the label on the center of the screen
pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
// add the label as a child to this layer
this->addChild(pLabel, 1);
// add "HelloWorld" splash screen"
CCSprite* pSprite = CCSprite::create("Untitled1.png");
// position the sprite on the center of the screen
pSprite->setPosition( ccp(size.width/2, size.height/2) );
// add the sprite as a child to this layer
this->addChild(pSprite, 0);
CCSprite* player = CCSprite::create("Player.png", CCRectMake(0, 0, 27, 50));
player->setPosition(ccp(player->getContentSize().width/2, size.height/2));
this->addChild(player);
bRet = true;
} while (0);
return bRet;
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
HelloWorldScene.h
#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__