zoukankan      html  css  js  c++  java
  • Cocos2d-x 开发小记(二):控件

    //纯色色块控件(锚点默认左下角)
    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"); }
  • 相关阅读:
    【转载】数据杂谈
    【转载】行走在网格之间:微博用户关系模型
    【转载】TalkingData首席金融行业专家鲍忠铁:18亿数据解读移动互联网
    【转载】大数据架构和模式
    【转载】Deep Learning(深度学习)学习笔记整理
    【转载】如何组建一支优秀的数据分析团队?
    【转载】Hadoop可视化分析利器之Hue
    【转载】关于烂代码的那些事
    【转载】6个用好大数据的秘诀
    【转载】如何一步步从数据产品菜鸟走到骨干数据产品
  • 原文地址:https://www.cnblogs.com/linji/p/3599912.html
Copyright © 2011-2022 走看看