1.多彩的幕布CCLayerColor,CCLayerGradient
1.多彩的幕布(CCLayerColor)
| ColorLayer.h |
| #ifndef_COLORLAYER_H_ #define_COLORLAYER_H_ ? #include"cocos2d.h" USING_NS_CC; ? //多彩的幕布layer,這時候要使用繼承CCLayerColor //默認的CCLayer是透明的 classColorLayer :publicCCLayerColor { public: ???staticCCScene *scene(); ???CREATE_FUNC(ColorLayer); ???boolinit(); }; ? #endif |
| ColorLayer.cpp |
| #include"ColorLayer.h" #include"AppMacros.h" ? CCScene *ColorLayer::scene() { ???//先創建一個場景 ???CCScene *scene =CCScene::create(); ???//再創建一個層 ???ColorLayer *layer =ColorLayer::create(); ???//添加一個層 ???scene->addChild(layer); ???returnscene; } ? boolColorLayer::init() { ???//ccc4(255,255,255,255),200,200?表示顏色使用白色,寬度200,長度200 ???CCLayerColor::initWithColor(ccc4(255,255,255,255),200,200); ???//表示不忽略錨點 ???ignoreAnchorPointForPosition(false); ???returntrue; } |
| 運行結果:
|
2漸變的Layer
| LayerGradient.h |
| #ifndef_LAYERGRADIENT_H_ #define_LAYERGRADIENT_H_ #include"cocos2d.h" USING_NS_CC; ? //通過這個類實現有色Layer的漸變效果 classLayerGradient :publicCCLayerGradient { public: ???staticCCScene *scene(); ???CREATE_FUNC(LayerGradient); ???boolinit(); }; ? #endif |
| LayerGradient.cpp |
| #include"LayerGradient.h" CCScene *LayerGradient::scene() { ???//創建一個場景 ???CCScene *scene =CCScene::create(); ???//創建一個layer ???LayerGradient *layer =LayerGradient::create(); ???//場景中添加層 ???scene->addChild(layer); ???returnscene; } ? boolLayerGradient::init() { ???//ccc4(255,0,0,255),ccc4(0,0,255,255),ccp(0,1)??前兩個ccc4分別表示兩種顏色 ???//cpp(0,1)表示的是顏色的漸變方向 ???CCLayerGradient::initWithColor(ccc4(255,150,0,255),ccc4(0,150,15,255),ccp(4,1)); ???returntrue; } |
| 運行效果:
|
3 API介紹
| CCLayerColor |
| //將Layer設置成統一的顏色 bool CCLayerColor::initWithColor(const ccColor4B& color); //通過后面兩個參數可以設置設置顏色的Layer的寬度和高度 bool CCLayerColor::initWithColor(const ccColor4B& color, GLfloat w,GLfloat h); |
| CCLayerGradient |
| //設置兩個漸變顏色 bool CCLayerGradient::initWithColor(const ccColor4B& start, const ccColor4B& end); //設置兩個漸變顏色,并通過最后的const CCPoint設置漸變的方向 bool CCLayerGradient::initWithColor(const ccColor4B& start, const ccColor4B& end, const CCPoint& v); 例如: CCLayerGradient::initWithColor(ccc4(123,89,0,255),ccc4(0,255,255,255),ccp(1,0)); |
?
總結
以上是生活随笔為你收集整理的1.多彩的幕布CCLayerColor,CCLayerGradient的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 002945上市时间
- 下一篇: 2.cocos2d-x坐标体系(UI坐标