I am having some difficulty with creating a custom class based upon CCLayerColor and having it work.
Using the Hello World as an example.
This works:
// background
CCLayerColor *background = CCLayerColor::create(cGhostWhite);
background->setContentSize(CCSizeMake(1024, 768));
background->setPosition(0,0);
this->addChild(background,0);
But trying to make my own custom class as:
.h:
#ifndef __PLAINBACKGROUNDLAYER_H__
#define __PLAINBACKGROUNDLAYER_H__
#include "cocos2d.h"
#include "Box2D.h"
class PlainBackgroundLayer : public cocos2d::CCLayerColor
{
public:
PlainBackgroundLayer(cocos2d::ccColor4B inColor);
~PlainBackgroundLayer();
virtual void draw();
private:
cocos2d::ccColor4B backgroundColor;
cocos2d::CCSize layerSize;
cocos2d::CCLayerColor *background;
};
#endif // __PLAINBACKGROUNDLAYER_H__
.cpp:
#include "PlainBackgroundLayer.h"
using namespace cocos2d;
PlainBackgroundLayer::PlainBackgroundLayer(cocos2d::ccColor4B inColor)
{
layerSize = CCDirector::sharedDirector()->getWinSize();
backgroundColor = inColor;
background = CCLayerColor::create(backgroundColor);
background->setContentSize(CCSizeMake(1024, 768));
background->setPosition(0,0);
}
and instantiating in a .cpp like this:
PlainBackgroundLayer *background = new PlainBackgroundLayer::PlainBackgroundLayer(cGhostWhite4B);
this->addChild(background,0);
I dont get what I expect showing. Just blank.
I have even tried like:
#include "PlainBackgroundLayer.h"
using namespace cocos2d;
PlainBackgroundLayer::PlainBackgroundLayer(cocos2d::ccColor4B inColor)
{
layerSize = CCDirector::sharedDirector()->getWinSize();
backgroundColor = inColor;
this->CCLayerColor::create(backgroundColor);
this->setContentSize(CCSizeMake(1024, 768));
this->setPosition(0,0);
}
and:
#include "PlainBackgroundLayer.h"
using namespace cocos2d;
PlainBackgroundLayer::PlainBackgroundLayer(cocos2d::ccColor4B inColor)
{
layerSize = CCDirector::sharedDirector()->getWinSize();
backgroundColor = inColor;
CCLayerColor::create(backgroundColor);
setContentSize(CCSizeMake(1024, 768));
setPosition(0,0);
}
There is a concept that I am missing. Can anyone help me understand?