1.多彩的幕布CCLayerColor,CCLayerGradient
1.多彩的幕布(CCLayerColor)
| ColorLayer.h |
| #ifndef_COLORLAYER_H_ #define_COLORLAYER_H_ ? #include"cocos2d.h" USING_NS_CC; ? //多彩的幕布layer,這時候要使用繼承CCLayerColor //默認(rèn)的CCLayer是透明的 classColorLayer :publicCCLayerColor { public: ???staticCCScene *scene(); ???CREATE_FUNC(ColorLayer); ???boolinit(); }; ? #endif |
| ColorLayer.cpp |
| #include"ColorLayer.h" #include"AppMacros.h" ? CCScene *ColorLayer::scene() { ???//先創(chuàng)建一個場景 ???CCScene *scene =CCScene::create(); ???//再創(chuàng)建一個層 ???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); ???//表示不忽略錨點(diǎn) ???ignoreAnchorPointForPosition(false); ???returntrue; } |
| 運(yùn)行結(jié)果:
|
2漸變的Layer
| LayerGradient.h |
| #ifndef_LAYERGRADIENT_H_ #define_LAYERGRADIENT_H_ #include"cocos2d.h" USING_NS_CC; ? //通過這個類實(shí)現(xiàn)有色Layer的漸變效果 classLayerGradient :publicCCLayerGradient { public: ???staticCCScene *scene(); ???CREATE_FUNC(LayerGradient); ???boolinit(); }; ? #endif |
| LayerGradient.cpp |
| #include"LayerGradient.h" CCScene *LayerGradient::scene() { ???//創(chuàng)建一個場景 ???CCScene *scene =CCScene::create(); ???//創(chuàng)建一個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; } |
| 運(yùn)行效果:
|
3 API介紹
| CCLayerColor |
| //將Layer設(shè)置成統(tǒng)一的顏色 bool CCLayerColor::initWithColor(const ccColor4B& color); //通過后面兩個參數(shù)可以設(shè)置設(shè)置顏色的Layer的寬度和高度 bool CCLayerColor::initWithColor(const ccColor4B& color, GLfloat w,GLfloat h); |
| CCLayerGradient |
| //設(shè)置兩個漸變顏色 bool CCLayerGradient::initWithColor(const ccColor4B& start, const ccColor4B& end); //設(shè)置兩個漸變顏色,并通過最后的const CCPoint設(shè)置漸變的方向 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)); |
?
總結(jié)
以上是生活随笔為你收集整理的1.多彩的幕布CCLayerColor,CCLayerGradient的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 002945上市时间
- 下一篇: 申请了贷款卡号错了怎么办