cocos2d-x CCControlButton,九妹图用按钮
2014-12-30 20:55
459 查看
<pre name="code" class="cpp">/************************************************************************/ /* CCControlButton 固定宽高的函数是: setAdjustBackgroundImage(false) 按钮按下时改变按钮文字的颜色: setTileColorForState(ccWHITE,CCControlStateHighlighted); CCControlStateHighlighted表示按钮被单击处于高亮状态时改变按钮文字的颜色为前面指定的颜色; */ /************************************************************************/ bool bRet = false; do { //这样写比较保险: CC_BREAK_IF(!CCLayer::init());//此宏只能在循环里调用;用来代替 if () break;
//正常状态下的按钮图片; CCScale9Sprite * btnNormal = CCScale9Sprite::create("scale9.png"); //单击状态下的图片; CCScale9Sprite * btnDown = CCScale9Sprite::create("10.png"); //按钮标题文字; CCLabelTTF * title = CCLabelTTF::create("Touch Me!3334444443", "courier new", 30); //创建按钮,按钮的大小会根据标题自动调整; CCControlButton * controlBtn = CCControlButton::create(title, btnNormal); //设置按钮按下时的图片; controlBtn->setBackgroundSpriteForState(btnDown, CCControlStateSelected); controlBtn->setPosition(ccp(200,200)); //固定背景大小;虽然有说会自动变大,但是我用的没效果; controlBtn->setPreferredSize(CCSize(200,200)); this->addChild(controlBtn); //点击事件; controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(CCScale::touchDownAction), CCControlEventTouchDown); //点击事件; /************************************************************************/ /* 当鼠标处于按下并曾经点中按钮时,则触发一次 void touchDownAction(CCObject* pSender, CCControlEvent event); CCControlEventTouchDown 当鼠标处于按下并曾经点中按钮的状态下,鼠标进入按钮范围,则触发一次 void touchDragEnter(CCObject* pSender, CCControlEvent event); CCControlEventTouchDragEnter 当鼠标处于按下并曾经点中按钮的状态下,鼠标离开按钮范围,则触发一次 void touchDragExit(CCObject* pSender, CCControlEvent event); CCControlEventTouchDragExit 当鼠标处于按下并曾经点中按钮的状态下,鼠标进入按钮范围,则触发,只要达到条件,就不断触发 void touchDragInside(CCObject* pSender, CCControlEvent event); CCControlEventTouchDragInside 当鼠标处于按下并曾经点中按钮的状态下,鼠标离开按钮范围,则触发,只要达到条件,就不断触发 void touchDragOutside(CCObject* pSender, CCControlEvent event); CCControlEventTouchDragOutside 当鼠标处于按下并曾经点中按钮的状态下,鼠标松开且在按钮范围内,则触发一次 void touchUpInside(CCObject* pSender, CCControlEvent event); CCControlEventTouchUpInside 当鼠标处于按下并曾经点中按钮的状态下,鼠标松开且在按钮范围外,则触发一次 void touchUpOutside(CCObject* pSender, CCControlEvent event); CCControlEventTouchUpOutside 暂时没有发现能用鼠标触发这个事件的操作,看了注释,应该是由其它事件中断按钮事件而触发的 void touchCancel(CCObject* pSender, CCControlEvent event); CCControlEventTouchCancel */ /************************************************************************/ bRet = true; } while (0); void touchDownAction(CCObject* pSender, CCControlEvent event) { CCSprite * spr = CCSprite::create("10.png"); addChild(spr); spr->setPosition(ccp(200,200)); }
相关文章推荐
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x 在CCTableview里面添加按钮效果,CCMenu,CCSprite,CCControlButton
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x按钮CCControlButton的用法
- 【Cocos2d-x】CCControlButton状态按钮的使用
- 10 cocos2d-x 按钮 CCControlButton
- Cocos2d-x学习笔记(12)(CCControlSwitch开关、CCControlSlider滑动条、CCControlButton按钮)
- cocos2d-x按钮CCControlButton的用法
- Cocos2d-x 按钮 CCControlButton 的 用法
- cocos2d-x 常用代码、高频使用代码【CCLayer、CCEditBox编辑框、CCControlButton按钮、CCLabelTTF标签、CCSpriteBatchNode渲染、CCMen】
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x 3.3 按钮添加和事件(CCControlButton)
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x按钮CCControlButton的用法
- cocos2d-x按钮CCControlButton的用法
- Cocos2d-x_CCControlButton(按钮类)介绍
- 我的Cocos2d-x学习笔记(十五)CCControlSlider、CCControlSwitch、CCScale9Sprite、CCControlButton
- 【Cocos2dx】使用CCControlButton创建按钮、按钮点击事件,点击事件中的组件获取,setPosition的坐标问题