Created
February 4, 2015 16:34
-
-
Save tklee1975/e19cc6268da00d87ce0e to your computer and use it in GitHub Desktop.
Sample Sub class of LayerColor in cocos2d-x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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