zoukankan      html  css  js  c++  java
  • cocos2dx CCControlButton button大事

    =================================.cpp文件

    <pre name="code" class="cpp">bool HelloWorld::init() { 
        if ( !CCLayer::init() ) { 
            return false;
        } 
        CCLabelTTF * label = CCLabelTTF::create("为选中文字", "MarkerFelt",25); 
        CCControlButton * button = CCControlButton ::create(label,CCScale9Sprite::create("button.png")); 
        button->setPosition(ccp(240, 170)); 
        // 按钮选中后背景图响应的状态 
        button->setTitleColorForState(ccc3(255, 0, 0), CCControlStateHighlighted);
        // 按钮选中后文字响应的状态 
        button->setTitleForState(CCString::create("选中文字"), CCControlStateHighlighted); addChild(button); 
        // 按下按钮事件回调 
        button->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDownAction), CCControlEventTouchDown); 
        // 按钮在其内部拾起事件回调 
        button->addTargetWithActionForControlEvents(this , cccontrol_selector( HelloWorld::touchUpInsideAction), CCControlEventTouchDragEnter); 
        // 按钮在其外部拾起事件回调 button->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::touchUpOutsideAction), CCControlEventTouchDragOutside); 
        // 用于显示按钮的状态 
        CCLabelTTF * la = CCLabelTTF ::create(" ", "MarkerFelt",20); 
        la->setColor(ccc3(255, 0, 0)); 
        la->setPosition(ccp(240, 220)); 
        addChild(la,0,923); 
        
        return true; 
    } 
    // 按下按钮事件回调 
    void HelloWorld:: touchDownAction(CCObject * sender , CCControlEvent * controlEvent)
    { 
        CCLabelTTF * label = (CCLabelTTF*) this ->getChildByTag(923);
        label->setString(CCString::createWithFormat("按下")->getCString()); 
    } 
    // 按钮在其内部抬起事件回调 
    void HelloWorld::touchUpInsideAction(CCObject * sender , CCControlEvent * controlEvent) { 
        CCLabelTTF * label = (CCLabelTTF*) this ->getChildByTag(923); 
        label->setString(CCString::createWithFormat("内部抬起")->getCString()); 
    } 
    // 按钮在其外部抬起事件回调 
    void HelloWorld::touchUpOutsideAction(CCObject * sender , CCControlEvent * controlEvent) { 
        CCLabelTTF * label = (CCLabelTTF*) this ->getChildByTag(923); 
        label->setString(CCString::createWithFormat("外部抬起")->getCString()); 
    }
    ==========================.h文件

    
    
    <pre name="code" class="cpp">.h文件
    #include "cocos2d.h" #include "cocos-ext.h" 
    using namespace cocos2d; 
    using namespace extension; 
    class HelloWorld : public cocos2d::CCLayer { 
    public: 
    virtual bool init(); 
    static cocos2d::CCScene* scene(); 
    void menuCloseCallback(CCObject* pSender); 
    CREATE_FUNC(HelloWorld); 
    // 按下button事件回调 
    void touchDownAction(CCObject * sender , CCControlEvent * controlEvent); 
    // button在其内部拾起事件回调 
    void touchUpInsideAction(CCObject * sender , CCControlEvent * controlEvent); 
    // button在其外部拾起事件回调 
    void touchUpOutsideAction(CCObject * sender , CCControlEvent * controlEvent); 
    };




    
    

    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    【摘】IIS修复工具,怎么完全卸载IIS
    开启@yahoo.cn邮箱POP和SMTP的方法
    IT男士专用餐单(养生)
    使用wxWidgets编程——第一步
    搭建跨平台编程环境Code::Blocks+wxWidgets
    TANGO是一个开源的分布控制系统
    【摘】在Window下右键方式打开Dos命令窗口右键菜单支持DOS命令提示符号
    【原】美是永远的追求
    flascc移植问题流水账
    战棋游戏三国志英杰传分析
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4843206.html
Copyright © 2011-2022 走看看