Cocos2d-x_CCControlButton(按钮类)介绍
2014-10-20 14:17
453 查看
// // HelloWorldScene.h // #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" #include "cocos-ext.h" USING_NS_CC; USING_NS_CC_EXT; class HelloWorld : public cocos2d::CCLayer { public: virtual bool init(); static cocos2d::CCScene* scene(); CREATE_FUNC(HelloWorld); void touchDownAction(CCObject *pSender, CCControlEvent controlEvent); void touchUpInsideAction(CCObject *pSender, CCControlEvent controlEvent); void touchUpOutsideAction(CCObject *pSender, CCControlEvent controlEvent); }; #endif
// // HelloWorldScene.cpp // #include "HelloWorldScene.h" USING_NS_CC; CCScene* HelloWorld::scene() { CCScene *scene = CCScene::create(); HelloWorld *layer = HelloWorld::create(); scene->addChild(layer); return scene; } bool HelloWorld::init() { if ( !CCLayer::init() ) { return false; } CCLabelTTF *ttf = CCLabelTTF::create("未选中文字", "MarkerFelt", 25); CCScale9Sprite *bgSpr = CCScale9Sprite::create("button.png"); CCControlButton *ccBtn = CCControlButton::create(ttf, bgSpr); ccBtn->setPosition(ccp(240, 170)); ccBtn->setBackgroundSpriteForState(CCScale9Sprite::create("buttonHighlighted.png"), CCControlStateHighlighted); ccBtn->setTitleColorForState(ccc3(255, 0, 0), CCControlStateHighlighted); ccBtn->setTitleForState(CCString::create("选中文字"), CCControlStateHighlighted); ccBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDownAction), CCControlEventTouchDown); ccBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchUpInsideAction), CCControlEventTouchUpInside); ccBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchUpOutsideAction), CCControlEventTouchUpOutside); this->addChild(ccBtn); CCLabelTTF *ttfBtnState = CCLabelTTF::create("", "MarkerFelt", 25); ttfBtnState->setPosition(ccp(240, 220)); this->addChild(ttfBtnState,0,293); return true; } void HelloWorld::touchDownAction(cocos2d::CCObject *pSender, CCControlEvent controlEvent) { CCLabelTTF *ttf = (CCLabelTTF *)this->getChildByTag(293); ttf->setString("按下"); } void HelloWorld::touchUpInsideAction(cocos2d::CCObject *pSender, CCControlEvent controlEvent) { CCLabelTTF *ttf = (CCLabelTTF *)this->getChildByTag(293); ttf->setString("内部抬起"); } void HelloWorld::touchUpOutsideAction(cocos2d::CCObject *pSender, CCControlEvent controlEvent) { CCLabelTTF *ttf = (CCLabelTTF *)this->getChildByTag(293); ttf->setString("外部抬起"); }
相关文章推荐
- cocos2d-x 常用代码、高频使用代码【CCLayer、CCEditBox编辑框、CCControlButton按钮、CCLabelTTF标签、CCSpriteBatchNode渲染、CCMen】
- cocos2d-x CCControlButton,九妹图用按钮
- cocos2d-x 在CCTableview里面添加按钮效果,CCMenu,CCSprite,CCControlButton
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x按钮CCControlButton的用法
- Cocos2d-x学习笔记(12)(CCControlSwitch开关、CCControlSlider滑动条、CCControlButton按钮)
- cocos2d-x按钮CCControlButton的用法
- Cocos2d-x 按钮 CCControlButton 的 用法
- 10 cocos2d-x 按钮 CCControlButton
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x 3.3 按钮添加和事件(CCControlButton)
- 【Cocos2d-x】CCControlButton状态按钮的使用
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x按钮CCControlButton的用法
- Cocos2d-x UI开发之CCControlButton控件类实例
- cocos2d-x tableview和CCControlButton的使用