新建项目以后,只需要修改....Scene.cpp的代码即可
#include "HelloWorldScene.h" using namespace cocos2d; CCScene* HelloWorld::scene() { CCScene * scene = NULL; do { // 'scene' is an autorelease object scene = CCScene::node(); CC_BREAK_IF(! scene); // 'layer' is an autorelease object HelloWorld *layer = HelloWorld::node(); CC_BREAK_IF(! layer); // add layer as a child to scene scene->addChild(layer); } while (0); // return the scene return scene; } // on "init" you need to initialize your instance bool HelloWorld::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayer::init()); ////////////////////////////////////////////////////////////////////////// // add your codes below... ////////////////////////////////////////////////////////////////////////// /* 颜色涂层 */ CCLayerColor* colorLayer = CCLayerColor::layerWithColor(ccc4f(255,255,0,255)); //this->addChild(colorLayer); /* 渐变色图层 CCLayerGradient::layerWithColor(ccc4f(255,0,0,255),ccc4f(0,255,0,255),ccp(0.8,0.8)) 3个参数分别为:开始颜色、结束颜色、颜色改变的点 需要注意的是颜色改变的点的两个参数都以比例的形式给出。 如这里的ccp(0.8,0.8)中的0.8是指占x轴的0.8 */ CCLayerGradient* gradientLayer = CCLayerGradient::layerWithColor(ccc4f(255,0,0,255),ccc4f(0,255,0,255),ccp(0.8,0.8)); //this->addChild(gradientLayer); CCLayerMultiplex* grounLayer = CCLayerMultiplex::layerWithLayers(colorLayer,gradientLayer); this->addChild(grounLayer); //grounLayer->switchTo(1);//切换到索引为1的图层。(索引从0开始算) grounLayer->switchToAndReleaseMe(1);//与上一个的不同之处在于这个切换后会释放该图层的空间,而且可能会产生异常 bRet = true; } while (0); return bRet; } void HelloWorld::menuCloseCallback(CCObject* pSender) { // "close" menu item clicked CCDirector::sharedDirector()->end(); }