分类:cocos2d-x
2014-04-11 22:30
1435人阅读
收藏
举报
cocos2dx
- #include"TouchTest.h"
- TouchTest::TouchTest()
- {
- m_longProgress=false;
- }
- boolisTouch=false;
- boolisMoved=intpressTimes=0;
- inttouchCounts=0;
- voidTouchTest::updateSingleDelay(floatft)
- {
- if(touchCounts==1){
- onSingleCLick();
- touchCounts=0;
- }
- voidTouchTest::updateDoubleDelay(floatft)
- if(touchCounts==2)
- onDoubleClick();
- voidTouchTest::updatelongprogress(if(isTouch){
- pressTimes++;
- if(pressTimes>=2){
- true;
- onLongPressed();
- else
- pressTimes=0;
- longlongTouchTest::getCurrentTime()
- structtimevaltm;
- gettimeofday(&tm,NULL);
- return(long)(tm.tv_sec*1000+tm.tv_usec/1000);
- boolTouchTest::touchBegan(cocos2d::Touch*touch,cocos2d::Event*event)
- m_startPoint=touch->getLocation();
- isTouch=m_startTime=getCurrentTime();
- this->schedule(schedule_selector(TouchTest::updatelongprogress),1);
- returntrue;
- voidTouchTest::touchMoved(cocos2d::Touch*touch,cocos2d::Event*event)
- isMoved=PointcurPoint=touch->getLocation();
- onMove(curPoint);
- voidTouchTest::touchEnded(cocos2d::Touch*touch,255); font-weight:bold; background-color:inherit">this->unschedule(schedule_selector(TouchTest::updatelongprogress));
- //如果刚完成长按事件则把按下次数清零长按状态置空直接返回不继续执行
- if(m_longProgress){
- return;
- m_endPoint=touch->getLocation();
- longendTime=getCurrentTime();
- longtimeDis=endTime-m_startTime;
- E_SWIP_DIRdir=GetSwipDir(m_startPoint,m_endPoint,timeDis);
- if(dir!=E_INVAILD){
- onSwip(m_startPoint,dir);
- return;
- //做连击判断
- if(isMoved){
- if(touchCounts==2){
- onThreeClick();
- elsethis->scheduleOnce(schedule_selector(TouchTest::updateDoubleDelay),0.25);
- touchCounts++;
- if(touchCounts==0){
- this->scheduleOnce(schedule_selector(TouchTest::updateSingleDelay),255); background-color:inherit">}
#include<iostream>
- #include"cocos2d.h"
- USING_NS_CC;
- constintminSwipdistance=100;
- intminSwiptime=1000;
- intmaxClickedDis=20;
- enumE_SWIP_DIR
- E_INVAILD,
- E_LEFT,
- E_RIGHT,255); background-color:inherit">E_UP,255); background-color:inherit">E_DOWN
- };
- classTouchTest:publicLayer
- public:
- TouchTest();
- booltouchBegan(Touch*touch,Event*event);
- voidtouchMoved(Touch*touch,Event*event);
- voidtouchEnded(Touch*touch,255); font-weight:bold; background-color:inherit">voidtouchCancel(Touch*touch,255); font-weight:bold; background-color:inherit">voidonTouchesBegan(conststd::vector<Touch*>&touches,Event*unused_event);
- voidonTouchesMoved(voidonTouchesEnded(voidonTouchesCancelled(voidupdateSingleDelay(float);
- voidupdateDoubleDelay(float);
- voidupdatelongprogress(longgetCurrentTime();
- voidstopSchedule();
- private:
- E_SWIP_DIRGetSwipDir(Pointstart,Pointend,longtimeDis);
- public:
- virtualvoidonSingleCLick();
- voidonDoubleClick();
- voidonThreeClick();
- voidonLongPressed();
- voidonMove(Point);
- voidonSwip(Point,Point,E_SWIP_DIR);
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|