//对应参数 //1 颜色。 2 宽度 3高度 //anchior默认是左下角 CCLayerColor *cc = CCLayerColor::create(ccc4(255,0,0,128),200, 100); cc->changeWidthAndHeight(299, 100); ccc->setColor(ccc3(0,255,0)); ccc->setOpacity(255);
CCLayerGradient 渐变颜色控件
CCLayerGradient *gradient = CCLayerGradient::create(ccc4(255,0,0,255), ccc4(0,255,0,255), ccp(1,1)); //第3个参数是渐变的方向
文字和Menu控件
//字体选择 Lisu, SimSun, Microsoft YaHei CCLabelTTF *label = CCLabelTTF::create("Hello", "Lisu", 50); label->setColor(ccc3(255,255,0)); CCLabelTTF *label1 = CCLabelTTF::create("Hello","SimSun", 50, CCSize(480, 320), kCCTextAlignmentLeft, KCCVerticalTextAlignmentCenter);//最后2个参数。左对齐和垂直居中 //创建菜单项 //有回调函数 CCMenuItemLabel *mil1 = CCMenuItemLabel::create(label, this, menu_selector(HelloWorld::clickStart)); mil1.setPosition(ccp(240,160)); CCMenuItemLabel *mil2 = CCMenuItemLabel::create(label1); mil2.setPosition(ccp(240,100)); //创建图片的菜单项 //image1的图片为正常图片,image2得图片为点击图 CCMenuItemImage *image = CCMenuItemImage::create("image1","image2", this, menu_selector(HelloWorld::clickStart)); CCMenu *menu=CCMenu::create(mil1,mil2,mil3,NULL); menu->setPosition(ccp(0,0));
中文字体会有乱码出现。解决方法是把文字写进一个文档,统一读取
Menu回调函数的写法
void clickStart(cocos2d::CCObject *menuItem){};