头文件BackgroundLayer.h
#ifndef __BBACKGROUNDLAYER_H__#define __BBACKGROUNDLAYER_H__#include "cocos2d.h"NS_CC_BEGINclass 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 wrapT = 0); virtual bool init(const char* pszfilename,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 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 wrapT){ BackgroundLayer* pobLayer = new BackgroundLayer(); Size winSize = Director::getInstance()->getWinSize(); if (pobLayer && pobLayer->init(pszfilename,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,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,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源码:背景层封装类全部内容,希望文章能够帮你解决cocos2dx源码:背景层封装类所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)