cocos2dx原始碼:背景層封裝類
標頭檔案BackgroundLayer.h
#ifndef __BBACKGROUNDLAYER_H__
#define __BBACKGROUNDLAYER_H__
#include "cocos2d.h"
NS_CC_BEGIN
class BackgroundLayer : public LayerColor
{
protected:
GLuint m_wrapS;
GLuint m_wrapT;
public:
static BackgroundLayer* create(const Color4B& color);
static BackgroundLayer* create(const char* pszFileName, Size &winSize, GLuint wrapS = 0, GLuint wrapT = 0);
static BackgroundLayer* create(const char* pszFileName, GLuint wrapS = 0, GLuint wrapT = 0);
virtual bool init(const char* pszFileName, Size &winSize, GLuint wrapS, GLuint wrapT);
};
NS_CC_END
#endif
原始檔BackgroundLayer.cpp
#include "BackgroundLayer.h"
USING_NS_CC;
BackgroundLayer* BackgroundLayer::create(const char* pszFileName, Size &winSize, GLuint wrapS, GLuint wrapT)
{
BackgroundLayer* pobLayer = new BackgroundLayer();
if (pobLayer && pobLayer->init(pszFileName, winSize, wrapS, wrapT))
{
pobLayer->autorelease();
return pobLayer;
}
else
{
CC_SAFE_DELETE(pobLayer);
return NULL;
}
}
BackgroundLayer* BackgroundLayer::create(const char* pszFileName, GLuint wrapS, GLuint wrapT)
{
BackgroundLayer* pobLayer = new BackgroundLayer();
Size winSize = Director::getInstance()->getWinSize();
if (pobLayer && pobLayer->init(pszFileName, winSize, wrapS, wrapT))
{
pobLayer->autorelease();
return pobLayer;
}
else
{
CC_SAFE_DELETE(pobLayer);
return NULL;
}
}
BackgroundLayer* BackgroundLayer::create(const Color4B& color)
{
BackgroundLayer* pobLayer = new BackgroundLayer();
if (pobLayer && pobLayer->initWithColor(color))
{
pobLayer->autorelease();
return pobLayer;
}
else
{
CC_SAFE_DELETE(pobLayer);
return NULL;
}
}
bool BackgroundLayer::init(const char* pszFileName, Size &winSize, GLuint wrapS, GLuint wrapT)
{
if (LayerColor::init())
{
if (!wrapS && !wrapT)
{
Sprite* bgImage = Sprite::create(pszFileName);
if (bgImage)
{
Size bgImageSize = bgImage->getContentSize();
bgImage->setScale(winSize.width / bgImageSize.width, winSize.height / bgImageSize.height);
this->addChild(bgImage);
bgImage->setPosition(Point(winSize.width/2, winSize.height/2));
this->setContentSize(winSize);
return true;
}
}
else
{
Rect winRect(0, 0, winSize.width, winSize.height);
Sprite* bgImage = Sprite::create(pszFileName, winRect);
if (bgImage)
{
Texture2D::TexParams tp = {GL_LINEAR, GL_LINEAR, wrapS, wrapT};
bgImage->getTexture()->setTexParameters(tp);
Size bgImageSize = bgImage->getContentSize();
this->addChild(bgImage);
bgImage->setPosition(Point(winSize.width/2, winSize.height/2));
this->setContentSize(winSize);
return true;
}
}
}
return false;
}
相關文章
- cocos2dx封裝一個具有Layout功能的Point類 (提供原始碼)封裝原始碼
- AFN3.0封裝一層工具類封裝
- SpringBoot原始碼解析-controller層引數的封裝Spring Boot原始碼Controller封裝
- Flutter Dio原始碼分析(四)--封裝Flutter原始碼封裝
- cocos2dx原始碼:相框PhotoFrame原始碼
- JavaFx 生成二維碼工具類封裝Java封裝
- 封裝xunsearch類封裝
- JS 封裝類JS封裝
- 短視訊平臺原始碼,取驗證碼 封裝全部封裝好直接呼叫原始碼封裝
- cocos2dx原始碼:popup實現原始碼
- 封裝Date工具類封裝
- JsonValue 封裝類JSON封裝
- 封裝Redis工具類封裝Redis
- 爬蟲驗證碼的幾種處理方式,已封裝成類,文章末尾有原始碼!爬蟲封裝原始碼
- 視訊直播app原始碼,不同分類頂部背景色APP原始碼
- APIjson多層資料實體類封裝(利用泛型技術)APIJSON封裝泛型
- jquery div層拖動效果封裝jQuery封裝
- c#封裝DBHelper類C#封裝
- 4、類和物件—封裝物件封裝
- 自用驗證類封裝封裝
- 封裝獲取Class類封裝
- php的curl封裝類PHP封裝
- 一、類的封裝性封裝
- Java集合類,從原始碼解析底層實現原理Java原始碼
- 【Django drf】檢視類APIView之五層封裝 ApiView的類屬性 drf配置檔案DjangoAPIView封裝
- cocos2dx 很好的原始碼分析博文原始碼
- 一個C#封裝的加密解密類程式碼C#封裝加密解密
- 封裝JDBC—非框架開發必備的封裝類封裝JDBC框架
- 旅遊交友原始碼 旅行結伴原始碼 原始碼完全開源一同打包封裝APP原始碼封裝APP
- HTMLTestRunnerNew模組原始碼及呼叫自定義報告封裝HTML原始碼封裝
- YYModel 原始碼歷險記 對Class的封裝原始碼封裝
- 十五、類與封裝的概念封裝
- c# Lambda操作類封裝C#封裝
- Android Logcat 封裝類AndroidGC封裝
- http通訊類的封裝HTTP封裝
- Java併發集合類ConcurrentHashMap底層核心原始碼解析JavaHashMap原始碼
- 微信域名防封原始碼原始碼
- DRF終極封裝ViewSet和Router附教程PDF原始碼封裝View原始碼