zoukankan      html  css  js  c++  java
  • CCTextFieldTTF 与 5种常用CCMenuItem

    //继承(class HelloWorld : public cocos2d::CCLayer, public cocos2d::CCTextFieldDelegate)
    
    CCTextFieldTTF* textField = CCTextFieldTTF::textFieldWithPlaceHolder("Click input...", "Helvetica", 24); textField->setPosition(ccp(size.width*0.5,size.height*0.7)); addChild(textField); //绑定接口 textField->setDelegate(this); //开启输入 textField->attachWithIME(); //关闭输入 //textField->detachWithIME();

    5种常用CCMenuItem

    //----CCMenuItemImage                
            /*
            *CCMenuItemImage::create(const char *normalImage, const char *selectedImage, CCObject* target, SEL_MenuHandler selector)
            *
            *参1:正常显示的图片
            *参2:用户选中后显示图片
            *参3:触发的目标对象
            *参4:触发的目标函数
            */
            CCMenuItemImage *menuItemImage = CCMenuItemImage::create(
                "CloseNormal.png",
                "CloseSelected.png",
                this,
                menu_selector(HelloWorld::menuCloseCallback));
            CC_BREAK_IF(! menuItemImage);
            menuItemImage->setPosition(ccp(120,180));
    
            //----CCMenuItemFont
            /*
            *CCMenuItemFont * CCMenuItemFont::create(const char *value, CCObject* target, SEL_MenuHandler selector)
            *
            *参1:显示的文字
            *参2:触发的目标对象
            *参3:触发的目标函数
            */
            CCMenuItemFont* menuItemFont = CCMenuItemFont::create("ItemFont",this,menu_selector(HelloWorld::menuCloseCallback));
            CC_BREAK_IF(! menuItemFont);
            menuItemFont->setPosition(220, 180);
    
            //----CCMenuItemLabel
            /*
            *CCMenuItemLabel::create(CCNode*label, CCObject* target, SEL_MenuHandler selector)
            *
            *参1:CCLabelTTF 对象
            *参2:触发的目标对象
            *参3:触发的目标函数
            */
            CCLabelTTF* lableTTF = CCLabelTTF::create("ItemLabel", "Helvetica", 20); 
            CCMenuItemLabel* menuItemLabel = CCMenuItemLabel::create(lableTTF,this,menu_selector(HelloWorld::menuCloseCallback));
            CC_BREAK_IF(! menuItemLabel);
            menuItemLabel->setPosition(320,180);
    
            //----CCMenuItemSprite
            /*
            *CCMenuItemSprite::create(CCNode* normalSprite, CCNode* selectedSprite, CCObject* target, SEL_MenuHandler selector)
            *
            *参1:未选中的显示 CCSprite 对象
            *参2:选中的显示 CCSprite 对象
            *参3:触发的目标对象
            *参4:触发的目标函数
            */
            CCSprite* spNor = CCSprite::create("Icon.png");
            spNor->setColor(ccc3(255, 255, 0 ));
            CCSprite* spSelected =CCSprite::create("Icon.png");
            CCMenuItemSprite* spriteItem = CCMenuItemSprite::create(spNor,spSelected, this,menu_selector(HelloWorld::menuCloseCallback));
            spriteItem->setPosition(ccp(150,100));
    
            //----CCMenuItemToggle
            /*
            *CCMenuItemToggle::createWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...)
            *
            *参1:触发的目标对象
            *参2:触发的目标函数
            *参3:CCMenuItem 对象的可变参数列表
            */
            CCMenuItemFont * fontItem1 = CCMenuItemFont::create("Music ON");
            CCMenuItemFont * fontItem2 = CCMenuItemFont::create("Music OFF");
            CCMenuItemToggle* toggleItem = CCMenuItemToggle::createWithTarget(this,NULL/*menu_selector(HelloWorld::menuCloseCallback)*/, fontItem1,fontItem2,NULL);
            toggleItem->setPosition(ccp(300,100));
    
    
            CCMenu* pMenu = CCMenu::create(menuItemImage, menuItemFont, menuItemLabel, spriteItem, toggleItem, NULL);
            pMenu->setPosition(CCPointZero);
            CC_BREAK_IF(! pMenu);
    
            this->addChild(pMenu, 1);
  • 相关阅读:
    TOJ 2710: 过河 路径压缩
    树状数组模板
    TOJ 2017: N-Credible Mazes
    TOJ 4804: 树网的核
    Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
    Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)
    TOJ 2541: Paper Cutting
    CODE FESTIVAL 2017 qual B
    hiho[Offer收割]编程练习赛30
    Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
  • 原文地址:https://www.cnblogs.com/MrGreen/p/3432120.html
Copyright © 2011-2022 走看看