cocos2d-x之触摸的响应
2014-07-03 20:25
127 查看
1. BoundingBox : CCNode的一个属性,返回精灵的边界。
CCNode‘s attribute , return the side of sprite
2. getContentSize :每一个精灵都被看成是一个矩形,具有长和宽,单位是point,返回的是矩形的大小。
every sprite is regarded as a rectangle,includes length and width,unit is point,return the size of rectangle.
3. setTouchEnabled(true);
setTouchMode(kCCTouchesOneByOne); //表示允许触摸 indicate we can touch
4. void registerWithTouchDispatcher(void);//注册触摸
bool ccTouchBegan(CCTouch* pTouch,CCEvent* pEvent); //触摸开始,注意返回类型,如果返回false,就不用写下面三个函数
void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);//触摸滑动
void
ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);//触摸结束
void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);//触摸取消,例如中途来点
开启触摸
在需要开启触摸的地方加入就行,例如init里面
bool Hello::init()
{
setTouchEnabled(true);
return true;
}
3、实现注册函数
void Hello::registerWithTouchDispatcher()
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
}
4、实现ccTouchBegan
bool Hello::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
CCLOG("touch began, touchpoint is %f", touchpoint);
return true; //true表示继续响应CCTouchMove,CCTouchEnd,CCTouchCancalled,false表示不响应。
}
5、实现ccTouchMove
void Hello::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
CCLOG("touch move, touchpoint is %f", touchpoint);
}
6、实现ccTouchEnded
void Hello::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
CCLOG("touch end, touchpoint is %f", touchpoint);
}
7、实现ccTouchCancalled
void Hello::ccTouchCancalled(CCTouch *pTouch, CCEvent *pEvent)
{
CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
CCLOG("touch end, touchpoint is %f", touchpoint);
}
CCNode‘s attribute , return the side of sprite
2. getContentSize :每一个精灵都被看成是一个矩形,具有长和宽,单位是point,返回的是矩形的大小。
every sprite is regarded as a rectangle,includes length and width,unit is point,return the size of rectangle.
3. setTouchEnabled(true);
setTouchMode(kCCTouchesOneByOne); //表示允许触摸 indicate we can touch
4. void registerWithTouchDispatcher(void);//注册触摸
bool ccTouchBegan(CCTouch* pTouch,CCEvent* pEvent); //触摸开始,注意返回类型,如果返回false,就不用写下面三个函数
void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);//触摸滑动
void
ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);//触摸结束
void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);//触摸取消,例如中途来点
开启触摸
在需要开启触摸的地方加入就行,例如init里面
bool Hello::init()
{
setTouchEnabled(true);
return true;
}
3、实现注册函数
void Hello::registerWithTouchDispatcher()
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
}
4、实现ccTouchBegan
bool Hello::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
CCLOG("touch began, touchpoint is %f", touchpoint);
return true; //true表示继续响应CCTouchMove,CCTouchEnd,CCTouchCancalled,false表示不响应。
}
5、实现ccTouchMove
void Hello::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
CCLOG("touch move, touchpoint is %f", touchpoint);
}
6、实现ccTouchEnded
void Hello::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
CCLOG("touch end, touchpoint is %f", touchpoint);
}
7、实现ccTouchCancalled
void Hello::ccTouchCancalled(CCTouch *pTouch, CCEvent *pEvent)
{
CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
CCLOG("touch end, touchpoint is %f", touchpoint);
}
相关文章推荐
- cocos2d-x场景中的层(CCLayer)及其触摸消息响应
- cocos2d ccLayer响应触摸事件方法:CCStandardTouchDelegate 与 CCTargetedTouchDelegate
- cocos2d屏幕部分区域无法响应触摸事件
- cocos2d-x总结(三)场景中的层(CCLayer)及其触摸消息响应
- 游戏开发随手记:cocos2d ccLayer响应触摸事件方法
- cocos2d ccLayer响应触摸事件方法:CCStandardTouchDelegate 与 CCTargetedTouchDelegate
- cocos2d-x总结 场景中的层(CCLayer)及其触摸消息响应
- cocos2d-x-教程 让精灵响应触摸 并把方向旋转到相对应的角度
- cocos2d ccLayer响应触摸事件方法:CCStandardTouchDelegate 与 CCTargetedTouchDelegate
- cocos2d-x学习之层的触摸消息响应
- cocos2d-x学习三触摸抬起响应喷发子弹
- cocos2d-x 触摸消息响应
- Cocos2D-x游戏开发之九:屏幕触摸一:基本屏幕操作响应
- cocos2d 触摸响应失效
- cocos2d-x 植物大战僵尸(6) 触摸植物卡的消息响应
- [cocos2d-x] 让精灵响应触摸 并把方向旋转到相对应的角度
- cocos2d-x学习之层的触摸消息响应
- Cocos2d-x游戏开发之2.x后弹出键盘后无法响应除键盘外的触摸事件解决
- cocos2d-x场景中的层(CCLayer)及其触摸消息响应
- Cocos2d-x ccSprite的触摸消息响应 - ccsx教程