微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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"); }
@H_502_5@ 

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐