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);
};
版权声明:本文博主原创文章,博客,未经同意不得转载。
cocos2dx CCControlButton button大事的更多相关文章
- lua 中处理cocos2dx 的button 事件
lua 中处理cocos2dx 的button 事件 2014-05-08 09:44:32| 分类: lua |举报 |字号 订阅 1.引入这个类:require "GuiConst ...
- Cocos2dx Widget button透明区域过滤
小伟哥 遇到一个命题: button透明区域过滤.当点击一个建筑button.花的时候不得不想一些方法把点击透明区域过滤掉. 让点击也没有效果滴啦. 開始搜索了半天才有所思路. 在网络上非常多贴代码的 ...
- 1cocos2dx扩展UI控制,CCControlSlider,CCScale9Sprite(九妹图。),CCControlSwitch,CCControlButton
UI控件来自cocos2dx的扩展库.完好了UI方面的元素,使cocos2dx更加丰富多彩.使用扩展库需包括: #include "cocos-ext.h" USING_NS ...
- Cocos2dx中的四种控件及主要用法
1.控件:即控制对象,控制按钮之类的精灵 2.主要介绍四大类控件: CCControlSlider:进度条 CCControlSwitch:开关 CCScale9Sprite:9妹图(用于缩放) CC ...
- Cocos2d-x之MenuItem
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- CCControlExtension/CCControlButton
#ifndef __CCCONTROL_BUTTON_H__ #define __CCCONTROL_BUTTON_H__ #include "CCControl.h" #incl ...
- GUI之CCControlExtension
Introduction CCControl is inspired by the UIControl API class from the UIKit library of CocoaTouch. ...
- cocos2dx基础篇(10) 按钮控件CCControlButton
[3.x] (1)去掉 “CC” (2)对象类 CCObject 改为 Ref (3)按钮事件回调依旧为 cccontrol_selector ,没有使用 CC_CALLBACK_2 (4)按钮状态 ...
- [cocos2dx笔记015]关于cocos2dx Button三种状态说明
经过几天的填坑,最终将现有的项目由cocos2dx 2.2.2移到cocos2dx 3.2,差点放弃3.2了,但在最后一刻,又把坑填平了. cocos2dx 2.x到3.x是一个巨大的变化,能够算是全 ...
随机推荐
- Hug the princess(思维,位运算)
Hug the princess Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) ...
- [转]Laravel 4之路由
Laravel 4之路由 http://dingjiannan.com/2013/laravel-routing/ Laravel 4路由是一种支持RESTful的路由体系, 基于symfony2的R ...
- css-文本及其他
<!DOCTYPE html>css7-文本和其他 text-align行内元素对齐方式,值为 左/中/右 对齐:left/right/center.test{text-align:cen ...
- MySQL的字符串函数截取字符
函数: 1.从左开始截取字符串 left(str, length) 说明:left(被截取字段,截取长度) 例:select left(content,200) as abstract from my ...
- sql server 删除所有表和存储过程
1.删除外键约束 DECLARE c1 cursor for select 'alter table ['+ object_name(parent_obj) + '] drop constraint ...
- Common Table Expressions (CTE)
子查询有时使用起来很麻烦,因为所有的过滤和匹配逻辑都必须集成到子查询表达式中.如果只需要执行一个任务,且只需要使用一次杳询表达式,子查询是很好的选择.但子查询不能被重用,也不能很好地支持多个需求.这个 ...
- 从几个sample来学习JAVA堆、方法区、JAVA栈和本地方法栈
最近在看<深入理解Java虚拟机>,书中给了几个例子,比较好的说明了几种OOM(OutOfMemory)产生的过程,大部分的程序员在写程序时不会太关注Java运行时数据区域的结构: 感觉有 ...
- static的用法解析
PHP中static变量的使用范围要更广一些,我们不仅可以在类,方法或变量前面添加static修饰符,我们甚至还能给函数内部变量添加static关键字.添加了static修饰符的变量即使在该函数执行完 ...
- MVC5学习相关资源整理
1 官方 Getting Started http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started 英文不好,英文好的同 ...
- mysql不能链接远程,报(Host '***.***.***.***' is not allowed to connect to this MySQL server)
Host '***.***.***.***' is not allowed to connect to this MySQL server 其中***...是本机公网ip; 解决办法: 首先看报错窗口 ...