Skip to content

Instantly share code, notes, and snippets.

@tklee1975
Created February 4, 2015 16:34
Show Gist options
  • Save tklee1975/e19cc6268da00d87ce0e to your computer and use it in GitHub Desktop.
Save tklee1975/e19cc6268da00d87ce0e to your computer and use it in GitHub Desktop.
Sample Sub class of LayerColor in cocos2d-x
//
// MyLayerColor.h
//
#include "cocos2d.h"
USING_NS_CC;
class MyLayerColor : public cocos2d::LayerColor
{
public:
static MyLayerColor *create(const Color4B& color, float width, float height);
virtual bool initWithColor(const cocos2d::Color4B &color, float width, float height);
};
#endif /* defined(__Shooter__MyLayerColor__) */
//
// MyLayerColor.cpp
//
#include "MyLayerColor.h"
MyLayerColor * MyLayerColor::create(const Color4B& color, float width, float height)
{
MyLayerColor * layer = new (std::nothrow) MyLayerColor();
if( layer && layer->initWithColor(color, width, height))
{
layer->autorelease();
return layer;
}
CC_SAFE_DELETE(layer);
return nullptr;
}
bool MyLayerColor::initWithColor(const cocos2d::Color4B &color, float width, float height)
{
//////////////////////////////
// 1. super init first
bool isOk = LayerColor::initWithColor(color, width, height);
if (isOk == false)
{
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment