love live 手游多点触控装修出了问题题 按长条的时候按其他键明明按下去了却没有反应 或者是有一

cocos2d-x 多点触控实现缩放及相关问题的解决方法
摘要: 首先要实现缩放这个逻辑,在ccTouchesBegan中检测,如果触摸点的个数大于两个,那么取前两个点,使用两点距离公式计算两点距离,在ccTouchesMoved中检测,如果触摸点的个数大于两个,那么继续计算这两个点的距离,然 ...
首先,来看下代码:声明文件:[cpp] #ifndef __loading__MoreTouches__ &#define __loading__MoreTouches__ && #include
&#include "cocos2d.h" &USING_NS_CC; &class MoreTouches :public CCLayer &{ &public: &&&& bool init(); &&&& //virtual void registerWithTouchDispather(void);&&& //由于是继承自CCLayer,这个方法就不用重写了,但下面几个方法还是要重写滴 &&&& virtual void ccTouchesCancellnd(CCSet *pTouches,CCEvent *pEvent); &&&& virtual void ccTouchesBegan(CCSet *pTouches,CCEvent *pEvent);//注意这个方法和单点触控方法的返回类型不同 &&&& virtual void ccTouchesEnded(CCSet *pTouches,CCEvent *pEvent); &&&& virtual void ccTouchesMoved(CCSet *pTouches,CCEvent *pEvent); &&&& static CCScene *scene(); &&&& virtual void onEnter(); &&&& virtual void onExit(); &&&& CREATE_FUNC(MoreTouches); &&&&& &public: &&&&&&& //两个触摸点之间的距离 &&&&&&& //目标x轴的改变值 &&&&&&& //目标y轴的改变值 &&&& CCSprite *&&&& //目标精灵 &&&&&& //初始地图缩放比例 &&&&& &}; && #endif /* defined(__loading__MoreTouches__) */ &定义文件:[cpp] #include "MoreTouches.h" && bool MoreTouches::init() &{ &&&& if(!CCLayer::init()) &&&& { &&&&&&&& &&&& } &&&& bg=CCSprite::create("fullbg.png");&& //初始化目标图片 &&&& this-&addChild(bg); && &&& mscale=1.0;&&&& //初始化图片的缩放比例 &&&& &} && //void MoreTouches::registerWithTouchDispather() &//{ &//&&& CCDirector::sharedDirector()-&getTouchDispatcher()-&addStandardDelegate(this, 0); &//} && void MoreTouches::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) &{ &&&& if(pTouches-&count()&=2)& //如果触摸点不少于两个 &&&& { &&&&&&&& CCSetIterator iter=pTouches-&begin(); &&&&&&&& CCPoint mPoint1=((CCTouch *)(*iter))-&getLocationInView(); &&&&&&&& mPoint1 = CCDirector::sharedDirector()-&convertToGL(mPoint1); &&&&&&&& iter++; &&&&&&&& CCPoint mPoint2=((CCTouch *)(*iter))-&getLocationInView(); &&&&&&&& mPoint2 = CCDirector::sharedDirector()-&convertToGL(mPoint2); &&&&&&&&& &&&&&&&& distance=sqrt((mPoint2.x-mPoint1.x)*(mPoint2.x-mPoint1.x)+(mPoint2.y-mPoint1.y)*(mPoint2.y-mPoint1.y));//计算两个触摸点距离 &&&&&&&& deltax = (mPoint1.x + mPoint2.x)/2 - bg-&getPositionX();&&&& //得到两个触摸点中点和精灵锚点的差值 &&&&&&&& deltay = (mPoint1.y + mPoint2.y)/2 - bg-&getPositionY(); &&&&&&&& CCLog("ccTouchesBegan& ..."); &&&&& &&&& } &} &void MoreTouches::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) &{ &&&& if(pTouches-&count()&=2)& //如果移动时触摸点的个数不少于两个 &&&& { &&&&&&&& CCSetIterator iter = pTouches-&begin(); &&&&&&&& CCPoint mPoint1 = ((CCTouch*)(*iter))-&getLocationInView(); &&&&&&&& mPoint1 = CCDirector::sharedDirector()-&convertToGL(mPoint1); &&&&&&&& iter++; &&&&&&&& CCPoint mPoint2 = ((CCTouch*)(*iter))-&getLocationInView(); &&&&&&&& mPoint2 = CCDirector::sharedDirector()-&convertToGL(mPoint2);&&&&&&& //获得新触摸点两点之间的距离 &&&&&&&& double mdistance = sqrt((mPoint1.x-mPoint2.x)*(mPoint1.x-mPoint2.x)+(mPoint1.y-mPoint2.y)*(mPoint1.y-mPoint2.y)); &&&&&&&& mscale = mdistance/distance *&&&&&&&&&&&&&&&&&&&&& //&& 新的距离 / 老的距离& * 原来的缩放比例,即为新的缩放比例 &&&&&&&& distance = &&&&&&&& bg-&setScale(mscale); &&&&&&&&& &&&&&&&& double x = (mPoint2.x+mPoint1.x)/2 -&&&&& //计算两触点中点与精灵锚点的差值 &&&&&&&& double y = (mPoint2.y+mPoint1.y)/2 - &&&&&&&& bg-&setPosition(ccp(x,y));&&&&&&&&&&&&&&&&&&&&&&& //保持两触点中点与精灵锚点的差值不变 &&&&&&&& deltax = (mPoint1.x+ mPoint2.x)/2 - bg-&getPositionX();&&&&&& //计算新的偏移量 &&&&&&&& deltay = (mPoint2.y + mPoint1.y)/2 - bg-&getPositionY(); &&&&&&&& CCLog("ccTouchMoved& ...."); &&&& } &&&& if(pTouches-&count()==1)&&&&&&&&&&&&&&&&&&&&&&&&& //如果触摸点为一个 &&&& { &&&&&&&& CCSetIterator iter =& pTouches-&begin(); &&&&&&&& CCPoint mPoint=((CCTouch*)(*iter))-&getLocationInView(); &&&&&&&& mPoint=CCDirector::sharedDirector()-&convertToGL(mPoint);&&& //坐标转换 &&&&&&&& bg-&setPosition(mPoint);&&&&&&&&&&&&&&&&&&& //直接移动精灵 &&&& } &} &void MoreTouches::ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) &{ &&&&& &} &void MoreTouches::ccTouchesCancellnd(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) &{ &&&&& &} &CCScene *MoreTouches::scene() &{ &&&& CCScene *scene=CCScene::create(); &&&& MoreTouches *layer=MoreTouches::create(); &&&& scene-&addChild(layer); &&&& &} &void MoreTouches::onEnter() &{ &&&& CCLayer::onEnter(); &&&& setTouchEnabled(true);CCLog("onenter"); &} &void MoreTouches::onExit() &{ &&&& CCLayer::onExit(); &&&& CCDirector::sharedDirector()-&getTouchDispatcher()-&removeDelegate(this);&&&& //移除触摸代理 &} &&&&&&&& 首先要实现缩放这个逻辑,在ccTouchesBegan中检测,如果触摸点的个数大于两个,那么取前两个点,使用两点距离公式计算两点距离,在ccTouchesMoved中检测,如果触摸点的个数大于两个,那么继续计算这两个点的距离,然后通过距离,计算得到缩放比例,调用setScale设置缩放比例即可。&&&&&&& 另外,除了缩放处理外,还需要处理位置问题,在ccTouchesBegan中计算两个触点的中点位置和精灵锚点的差,在ccTouchesMoved中,随着缩放,保持两触点中点和精灵锚点的差不变即可,ccTouchesEnded和ccTouchesCancelled中不需要修改。&&&&&&& 接下来,就重点说下在实现时遇到的问题吧,主要就一个,就是当在ios模拟器中操作时,我按着option键,可以出现两个点,但程序中始终只能得到一个点,即count=1,移动时也根本不能实现缩放。后来,终于谷歌出结果了,原来需要修改ios目录下的 AppController.mm文件[cpp] static AppDelegate s_sharedA &- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { &&&& // Override point for customization after application launch. &&&& // Add the view controller's view to the window and display. &&&& window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; &&&& EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& pixelFormat: kEAGLColorFormatRGBA8 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& depthFormat: GL_DEPTH_COMPONENT16 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& preserveBackbuffer: NO &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& sharegroup: nil &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& multiSampling: NO &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& numberOfSamples:0 ]; && &&& // Use RootViewController manage EAGLView &&&& viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; &&&& viewController.wantsFullScreenLayout = YES; &&&& viewController.view = __glV && &&& // Set RootViewController to window &&&& if ( [[UIDevice currentDevice].systemVersion floatValue] & 6.0) &&&& { &&&&&&&& // warning: addSubView doesn't work on iOS6 &&&&&&&& [window addSubview: viewController.view]; &&&& } &&&& else &&&& { &&&&&&&& // use this method on ios6 &&&&&&&& [window setRootViewController:viewController]; &&&& } &&&& [window makeKeyAndVisible]; &&&& [[UIApplication sharedApplication] setStatusBarHidden: YES]; &&&& cocos2d::CCApplication::sharedApplication()-&run(); &&&& [__glView setMultipleTouchEnabled:YES];&&& //主要就是这句了 &&&& return YES; &} &简单来说,就是:AppController.mm 里要启用多点触摸才可以,在- (BOOL)application:(UIApplication *)application添加[__glView setMultipleTouchEnabled:YES];这样,当我们按着option键和鼠标时,移动鼠标,就可以实现缩放了,当只用鼠标时,可以实现图片的移动,问题解决。
最新动态信息......
摘要: 首先要实现缩放这个逻辑,在ccTouchesBegan中检测,如果触摸点的个数大于两个,那么取前两个点,使用两点距离公式计算两点距离,在ccTouchesMoved中检测,如果触摸点的个数大于两个,那么继续计算这两个点的距离,然 ...
首先,来看下代码:声明文件:[cpp] #ifndef __loading__MoreTouches__ &#define __loading__MoreTouches__ && #include
&#include "cocos2d.h" &USING_NS_CC; &class MoreTouches :public CCLayer &{ &public: &&&& bool init(); &&&& //virtual void registerWithTouchDispather(void);&&& //由于是继承自CCLayer,这个方法就不用重写了,但下面几个方法还是要重写滴 &&&& virtual void ccTouchesCancellnd(CCSet *pTouches,CCEvent *pEvent); &&&& virtual void ccTouchesBegan(CCSet *pTouches,CCEvent *pEvent);//注意这个方法和单点触控方法的返回类型不同 &&&& virtual void ccTouchesEnded(CCSet *pTouches,CCEvent *pEvent); &&&& virtual void ccTouchesMoved(CCSet *pTouches,CCEvent *pEvent); &&&& static CCScene *scene(); &&&& virtual void onEnter(); &&&& virtual void onExit(); &&&& CREATE_FUNC(MoreTouches); &&&&& &public: &&&&&&& //两个触摸点之间的距离 &&&&&&& //目标x轴的改变值 &&&&&&& //目标y轴的改变值 &&&& CCSprite *&&&& //目标精灵 &&&&&& //初始地图缩放比例 &&&&& &}; && #endif /* defined(__loading__MoreTouches__) */ &定义文件:[cpp] #include "MoreTouches.h" && bool MoreTouches::init() &{ &&&& if(!CCLayer::init()) &&&& { &&&&&&&& &&&& } &&&& bg=CCSprite::create("fullbg.png");&& //初始化目标图片 &&&& this-&addChild(bg); && &&& mscale=1.0;&&&& //初始化图片的缩放比例 &&&& &} && //void MoreTouches::registerWithTouchDispather() &//{ &//&&& CCDirector::sharedDirector()-&getTouchDispatcher()-&addStandardDelegate(this, 0); &//} && void MoreTouches::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) &{ &&&& if(pTouches-&count()&=2)& //如果触摸点不少于两个 &&&& { &&&&&&&& CCSetIterator iter=pTouches-&begin(); &&&&&&&& CCPoint mPoint1=((CCTouch *)(*iter))-&getLocationInView(); &&&&&&&& mPoint1 = CCDirector::sharedDirector()-&convertToGL(mPoint1); &&&&&&&& iter++; &&&&&&&& CCPoint mPoint2=((CCTouch *)(*iter))-&getLocationInView(); &&&&&&&& mPoint2 = CCDirector::sharedDirector()-&convertToGL(mPoint2); &&&&&&&&& &&&&&&&& distance=sqrt((mPoint2.x-mPoint1.x)*(mPoint2.x-mPoint1.x)+(mPoint2.y-mPoint1.y)*(mPoint2.y-mPoint1.y));//计算两个触摸点距离 &&&&&&&& deltax = (mPoint1.x + mPoint2.x)/2 - bg-&getPositionX();&&&& //得到两个触摸点中点和精灵锚点的差值 &&&&&&&& deltay = (mPoint1.y + mPoint2.y)/2 - bg-&getPositionY(); &&&&&&&& CCLog("ccTouchesBegan& ..."); &&&&& &&&& } &} &void MoreTouches::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) &{ &&&& if(pTouches-&count()&=2)& //如果移动时触摸点的个数不少于两个 &&&& { &&&&&&&& CCSetIterator iter = pTouches-&begin(); &&&&&&&& CCPoint mPoint1 = ((CCTouch*)(*iter))-&getLocationInView(); &&&&&&&& mPoint1 = CCDirector::sharedDirector()-&convertToGL(mPoint1); &&&&&&&& iter++; &&&&&&&& CCPoint mPoint2 = ((CCTouch*)(*iter))-&getLocationInView(); &&&&&&&& mPoint2 = CCDirector::sharedDirector()-&convertToGL(mPoint2);&&&&&&& //获得新触摸点两点之间的距离 &&&&&&&& double mdistance = sqrt((mPoint1.x-mPoint2.x)*(mPoint1.x-mPoint2.x)+(mPoint1.y-mPoint2.y)*(mPoint1.y-mPoint2.y)); &&&&&&&& mscale = mdistance/distance *&&&&&&&&&&&&&&&&&&&&& //&& 新的距离 / 老的距离& * 原来的缩放比例,即为新的缩放比例 &&&&&&&& distance = &&&&&&&& bg-&setScale(mscale); &&&&&&&&& &&&&&&&& double x = (mPoint2.x+mPoint1.x)/2 -&&&&& //计算两触点中点与精灵锚点的差值 &&&&&&&& double y = (mPoint2.y+mPoint1.y)/2 - &&&&&&&& bg-&setPosition(ccp(x,y));&&&&&&&&&&&&&&&&&&&&&&& //保持两触点中点与精灵锚点的差值不变 &&&&&&&& deltax = (mPoint1.x+ mPoint2.x)/2 - bg-&getPositionX();&&&&&& //计算新的偏移量 &&&&&&&& deltay = (mPoint2.y + mPoint1.y)/2 - bg-&getPositionY(); &&&&&&&& CCLog("ccTouchMoved& ...."); &&&& } &&&& if(pTouches-&count()==1)&&&&&&&&&&&&&&&&&&&&&&&&& //如果触摸点为一个 &&&& { &&&&&&&& CCSetIterator iter =& pTouches-&begin(); &&&&&&&& CCPoint mPoint=((CCTouch*)(*iter))-&getLocationInView(); &&&&&&&& mPoint=CCDirector::sharedDirector()-&convertToGL(mPoint);&&& //坐标转换 &&&&&&&& bg-&setPosition(mPoint);&&&&&&&&&&&&&&&&&&& //直接移动精灵 &&&& } &} &void MoreTouches::ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) &{ &&&&& &} &void MoreTouches::ccTouchesCancellnd(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) &{ &&&&& &} &CCScene *MoreTouches::scene() &{ &&&& CCScene *scene=CCScene::create(); &&&& MoreTouches *layer=MoreTouches::create(); &&&& scene-&addChild(layer); &&&& &} &void MoreTouches::onEnter() &{ &&&& CCLayer::onEnter(); &&&& setTouchEnabled(true);CCLog("onenter"); &} &void MoreTouches::onExit() &{ &&&& CCLayer::onExit(); &&&& CCDirector::sharedDirector()-&getTouchDispatcher()-&removeDelegate(this);&&&& //移除触摸代理 &} &&&&&&&& 首先要实现缩放这个逻辑,在ccTouchesBegan中检测,如果触摸点的个数大于两个,那么取前两个点,使用两点距离公式计算两点距离,在ccTouchesMoved中检测,如果触摸点的个数大于两个,那么继续计算这两个点的距离,然后通过距离,计算得到缩放比例,调用setScale设置缩放比例即可。&&&&&&& 另外,除了缩放处理外,还需要处理位置问题,在ccTouchesBegan中计算两个触点的中点位置和精灵锚点的差,在ccTouchesMoved中,随着缩放,保持两触点中点和精灵锚点的差不变即可,ccTouchesEnded和ccTouchesCancelled中不需要修改。&&&&&&& 接下来,就重点说下在实现时遇到的问题吧,主要就一个,就是当在ios模拟器中操作时,我按着option键,可以出现两个点,但程序中始终只能得到一个点,即count=1,移动时也根本不能实现缩放。后来,终于谷歌出结果了,原来需要修改ios目录下的 AppController.mm文件[cpp] static AppDelegate s_sharedA &- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { &&&& // Override point for customization after application launch. &&&& // Add the view controller's view to the window and display. &&&& window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; &&&& EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& pixelFormat: kEAGLColorFormatRGBA8 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& depthFormat: GL_DEPTH_COMPONENT16 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& preserveBackbuffer: NO &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& sharegroup: nil &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& multiSampling: NO &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& numberOfSamples:0 ]; && &&& // Use RootViewController manage EAGLView &&&& viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; &&&& viewController.wantsFullScreenLayout = YES; &&&& viewController.view = __glV && &&& // Set RootViewController to window &&&& if ( [[UIDevice currentDevice].systemVersion floatValue] & 6.0) &&&& { &&&&&&&& // warning: addSubView doesn't work on iOS6 &&&&&&&& [window addSubview: viewController.view]; &&&& } &&&& else &&&& { &&&&&&&& // use this method on ios6 &&&&&&&& [window setRootViewController:viewController]; &&&& } &&&& [window makeKeyAndVisible]; &&&& [[UIApplication sharedApplication] setStatusBarHidden: YES]; &&&& cocos2d::CCApplication::sharedApplication()-&run(); &&&& [__glView setMultipleTouchEnabled:YES];&&& //主要就是这句了 &&&& return YES; &} &简单来说,就是:AppController.mm 里要启用多点触摸才可以,在- (BOOL)application:(UIApplication *)application添加[__glView setMultipleTouchEnabled:YES];这样,当我们按着option键和鼠标时,移动鼠标,就可以实现缩放了,当只用鼠标时,可以实现图片的移动,问题解决。
上一篇:下一篇:热血传奇手机版将再现曾经经典行会..
《最终幻想14》月卡今日开售 新版本..
刀塔传奇、乱斗西游等百款火爆手游..
《问道》2015年度新服今日开启 5万..
蜀黍我们不约!《龙界争霸》美女玩..
触手可及——北美游戏巨头 登陆亚洲..
狗仔队立功!《龙纹三国》新年计划..
《灵域》16日开放两组新服 玩家来领..
《英雄无敌-最强王者》二服10:00强..
当前位置:
靠谱助手支持多点触控 重度手游跨入电脑版时代
作家俱乐部
文人墨客:举人
文人墨客:举人
文人墨客:秀才
文人墨客:秀才
文人墨客:秀才
文人墨客:秀才
文人墨客:秀才
文人墨客:文士
文人墨客:文士
文人墨客:文士
文人墨客:文士
文人墨客:文士
全球游戏新闻
《最终幻想14》月卡今日开售 新版本..
手机游戏新闻
热血传奇手机版将再现曾经经典行会..
网页游戏新闻
夺冠之路强力典藏卡最后一天.2014话..
国内游戏新闻
《问道》2015年度新服今日开启 5万..
兄弟背后相助!大黑游戏《万世》门..
靠谱助手支持多点触控 重度手游跨入电脑版时代
一键分享:
看完这篇新闻有何感觉?已经有0人表态07-1107-1107-1107-1107-11
Copyright (C) .奇侠手游应用网小米手机快没电时屏幕有时会失灵,明明没有点屏幕又下角的位置,但每次触摸却都会有右下角被点的反应,_百度知道
小米手机快没电时屏幕有时会失灵,明明没有点屏幕又下角的位置,但每次触摸却都会有右下角被点的反应,
嗨!根据你描述的问题,在这里看不到你的手机是没法为你解决的。你的手机问题需要面对面的看到你的手机才能解决的。请你带上手机前往你附近的小米授权的维修点或者小米之家检测一下。授权维修网点地址和电话查询:。小米之家地址和电话查询小米之家工作时间为周二至周日,上午10点到晚上6点。
已回答940404
响应时间&16小时
其他类似问题
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 神武手游 的文章

 

随机推荐