http://blog.csdn.net/lnb333666/article/details/16857637
- //触屏事件
- virtualboolccTouchBegan(Touch*touch,Event*event);
- virtualvoidccTouchMoved(Touch*touch,Event*event);
- virtualvoidccTouchEnded(Touch*touch,226); color:inherit; line-height:18px">
- //生命周期
- virtualvoidonEnter();
- virtualvoidonExit();
- voidTouchdemo::onEnter()
- {
- //开启触屏监听
- Director::sharedDirector()->getTouchdispatcher()->addTargetedDelegate(this,false);
- Layer::onEnter();//一定不要忘了
- }
- voidTouchdemo::onExit()
- {
- //关闭触屏监听
- Director::sharedDirector()->getTouchdispatcher()->removeDelegate(this);
- Layer::onExit();//一定不要忘了
- }
- ===========================================================================================
- 添加委托
- addStandardDelegate();
- 开启多点触控(不写没有效果哦)
- setTouchEnabled();
- 触屏事件:
- 1.注册多点触控
- virtualvoidregisterWithTouchdispatcher(void);
- 2.当用户第一次触碰手机屏幕时响应的回调函数
- virtualvoidcctouchesBegan(Set*touchs,85); line-height:18px"> 3.当用户手指在手机屏幕上滑动时响应的回调函数
- virtualvoidcctouchesMoved(Set*touchs,226); color:inherit; line-height:18px"> 4.当用户手指在离开手机屏幕上时响应的回调函数
- virtualvoidcctouchesEnded(Set*touchs,0); background-color:inherit">//写上多点触控的回调函数
- virtualvoidcctouchesBegan(Set*set,Event*e);
- virtualvoidcctouchesMoved(Set*set,Event*e);
- virtualvoidcctouchesEnded(Set*set,0); background-color:inherit">//写上生命周期函数
- 注册监听
- voidTouchsdemo::registerWithTouchdispatcher(void)
- //注册监听
- Director::sharedDirector()->getTouchdispatcher()->addStandardDelegate(this,0);
- voidTouchsdemo::cctouchesBegan(Set*set,Event*e)
- SetIteratoriter=set->begin();
- //这里的iter相当于系统分配的数字,
- //set->begin()获取第一个数字
- //set->end()就是最后一位
- for(;iter!=set->end();iter++){
- //这里呢,就是单点处理了,可以理解为把多点拆成单点来做
- CTouch*mytouch=(Touch*)(*iter);
- Pointcp=mytouch->getLocation();
- //这里我们对5个触摸块进行处理
- if(mytouch->getID()==0){
- Sprite*sp=(Sprite*)this->getChildByTag(1);
- sp->setPosition(cp);
- if(mytouch->getID()==1){
- Sprite*sp=(Sprite*)this->getChildByTag(2);
- if(mytouch->getID()==2){
- Sprite*sp=(Sprite*)this->getChildByTag(3);
- if(mytouch->getID()==3){
- Sprite*sp=(CCSprite*)this->getChildByTag(4);
- if(mytouch->getID()==4){
- Sprite*sp=(Sprite*)this->getChildByTag(5);
- voidTouchsdemo::cctouchesEnded(Set*set,CCEvent*e)
- CCSetIteratoriter=set->begin();
- inta[6]={0,0};//创建一个数组
- Touch*mytouch=(Touch*)(*iter);
- Pointcp=mytouch->getLocation();
- //这里我们对5个触摸块进行处理
- if(mytouch->getID()==0){
- a[1]=1;
- a[2]=1;
- if(mytouch->getID()==2){
- a[3]=1;
- a[4]=1;
- if(mytouch->getID()==4){
- a[5]=1;
- for(inti=1;i<=5;i++){<>
- if(a[i]==1){
- Sprite*sp=(Sprite*)this->getChildByTag(i);
- sp->runAction(Moveto::create(5,ccp(30,30)));
- //实现生命周期函数
- voidTouchsdemo::onEnter()
- Layer::onEnter();
- voidTouchsdemo::onExit()
- Layer::onExit();
- }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。