#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);//与上一个的不同之处在于这个切换后会释放该图层的空间,而且可能会产生异常 /* CCLog():用于向控制台打印日志 this->getAnchorPoint() :获取当前图层或精灵的锚点 结论:图层或精灵(其他的也是这样,例如什么CCLayer)的默认锚点都是0.5、0.5 */ //CCSprite* sprite = CCSprite::spriteWithFile("CloseNormal.png"); //CCLog("layer:(%f , %f)",this->getAnchorPoint().x,this->getAnchorPoint().y); //CCLog("sprite:(%f , %f)",sprite->getAnchorPoint().x,this->getAnchorPoint().y); CCLayerColor* colorLayer1 = CCLayerColor::layerWithColorWidthHeight(ccc4f(255,0,0,255),480,320); this->addChild(colorLayer1); CCLog("colorLayer = (%f , %f)",colorLayer1->getAnchorPoint().x,colorLayer1->getAnchorPoint().y); colorLayer1->setPosition(ccp(240,160));//这两行的意思是:采用锚点作为作用点,将作用点的位置设为100,100 colorLayer1->setIsRelativeAnchorPoint(true);//如果不加这一行,那么意思就变成了“将当前作用点的位置设为100,100(默认是左下角)” colorLayer1->setAnchorPoint(ccp(0,0));//加上这一句话后,这三句话的意思就变成了:将锚点的坐标设为0,0;采用锚点作为作用点;将锚点移至240,160 bRet = true; } while (0); return bRet; } void HelloWorld::menuCloseCallback(CCObject* pSender) { // "close" menu item clicked CCDirector::sharedDirector()->end(); }