Cocos2d-x 开发小记二:控件

原文链接:http://www.cnblogs.com/linji/p/3599912.html
//纯色色块控件(锚点默认左下角)
CCLayerColor* ccc = CCLayerColor::create(ccc4(255, 0, 0, 128), 200, 100);

//渐变色块控件
CCLayerGradient* ccc = CCLayerGradient::create(ccc4(255, 0, 0, 255), ccc4(255, 255, 0, 255), ccp(1, 1));

ccc->changeWidth(400);    //改变宽度
ccc->changeHeight(200);    //改变高度
ccc->changeWidthAndHeight(400,200);    //同时改变宽高
ccc->setColor(ccc3(0, 255, 0));    //设置颜色
ccc->setOpacity(255);    //设置透明度
this->addChild(ccc);

//文本控件
CCLabelTTF* label = CCLabelTTF::create("Hello, I'm a good student, I like com", "Microsoft Yahei", 50, CCSize(240, 320), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter);

//菜单绑定
CCLabelTTF* label1 = CCLabelTTF::create("Start", "Microsoft Yahei", 50);  label1->setColor(ccc3(255, 255, 0));

CCLabelTTF* label2 = CCLabelTTF::create("Exit", "Microsoft Yahei", 50);  label2->setColor(ccc3(255, 255, 0));

//文本菜单项
CCMenuItemLabel* mil1 = CCMenuItemLabel::create(label1);  
mil1->setPosition(ccp(240, 160));
CCMenuItemLabel* mil2 = CCMenuItemLabel::create(label2);  
mil2->setPosition(ccp(240, 100));

//图片菜单项
CCMenuItemImage* mii1 = CCMenuItemImage::create();

CCMenu* menu = CCMenu::create(mil1, mil2, NULL); menu->setPosition(ccp(0, 0)); this->addChild(menu); //-------------------------------------------------------------------------------- //播放帧动画 //方法一 CCSpriteFrame* frame1 = CCSpriteFrame::create("menu/logo/1.png", CCRectMake(0, 0, 240, 190)); CCSpriteFrame* frame2 = CCSpriteFrame::create("menu/logo/2.png", CCRectMake(0, 0, 240, 190)); CCSpriteFrame* frame3 = CCSpriteFrame::create("menu/logo/3.png", CCRectMake(0, 0, 240, 190)); CCArray* frames = CCArray::create(frame1, frame2, frame3, NULL); CCAnimation* animation = CCAnimation::createWithSpriteFrames(frames, 1/20.0); CCAnimate* animate = CCAnimate::create(animation); CCSprite* sprite = CCSprite::create(); CCSprite* sprite = CCSprite::create(); sprite->setPosition(ccp(240, 160)); this->addChild(sprite); sprite->runAction(CCRepeatForever::create(animate)); //方法二 this->regPlay();  //注册动画
CCAnimation* animation1 = CCAnimationCache::sharedAnimationCache()->animationByName("play_logo"); CCSprite* sprite = CCSprite::create(); sprite->setPosition(ccp(240, 160)); this->addChild(sprite); sprite->runAction(CCRepeatForever::create(animation1)); void HelloWorldScene::regPlay() {   CCSpriteFrame* frame1 = CCSpriteFrame::create("menu/logo/1.png", CCRectMake(0, 0, 240, 190));   CCSpriteFrame* frame2 = CCSpriteFrame::create("menu/logo/2.png", CCRectMake(0, 0, 240, 190));   CCSpriteFrame* frame3 = CCSpriteFrame::create("menu/logo/3.png", CCRectMake(0, 0, 240, 190));   CCArray* frames = CCArray::create(frame1, frame2, frame3, NULL);   CCAnimation* animation = CCAnimation::createWithSpriteFrames(frames, 1/20.0);   CCAnimationCache::sharedAnimationCache()->addAnimation(animation,"play_logo"); }

 

转载于:https://www.cnblogs.com/linji/p/3599912.html

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...