日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

1.多彩的幕布CCLayerColor,CCLayerGradient

發布時間:2024/9/27 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。