<small id='MGAec'></small><noframes id='MGAec'>

  • <legend id='MGAec'><style id='MGAec'><dir id='MGAec'><q id='MGAec'></q></dir></style></legend>
    <i id='MGAec'><tr id='MGAec'><dt id='MGAec'><q id='MGAec'><span id='MGAec'><b id='MGAec'><form id='MGAec'><ins id='MGAec'></ins><ul id='MGAec'></ul><sub id='MGAec'></sub></form><legend id='MGAec'></legend><bdo id='MGAec'><pre id='MGAec'><center id='MGAec'></center></pre></bdo></b><th id='MGAec'></th></span></q></dt></tr></i><div id='MGAec'><tfoot id='MGAec'></tfoot><dl id='MGAec'><fieldset id='MGAec'></fieldset></dl></div>
    <tfoot id='MGAec'></tfoot>
      <bdo id='MGAec'></bdo><ul id='MGAec'></ul>

      1. cocos2D for iPhone 和触摸检测的问题

        时间:2024-08-12
        <tfoot id='gwKUo'></tfoot>

        <i id='gwKUo'><tr id='gwKUo'><dt id='gwKUo'><q id='gwKUo'><span id='gwKUo'><b id='gwKUo'><form id='gwKUo'><ins id='gwKUo'></ins><ul id='gwKUo'></ul><sub id='gwKUo'></sub></form><legend id='gwKUo'></legend><bdo id='gwKUo'><pre id='gwKUo'><center id='gwKUo'></center></pre></bdo></b><th id='gwKUo'></th></span></q></dt></tr></i><div id='gwKUo'><tfoot id='gwKUo'></tfoot><dl id='gwKUo'><fieldset id='gwKUo'></fieldset></dl></div>
          • <bdo id='gwKUo'></bdo><ul id='gwKUo'></ul>
                  <tbody id='gwKUo'></tbody>

                <small id='gwKUo'></small><noframes id='gwKUo'>

                  <legend id='gwKUo'><style id='gwKUo'><dir id='gwKUo'><q id='gwKUo'></q></dir></style></legend>

                  本文介绍了cocos2D for iPhone 和触摸检测的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我只是不明白.我使用 cocos2d 在 iPhone/Pod 上开发一个小游戏.该框架很棒,但我在触摸检测方面失败了.我读到您只需要在子类 CocosNode 的类的实现中覆盖正确的函数(例如touchesBegan").但它不起作用.我会做错什么?

                  I just don't get it. I use cocos2d for development of a small game on the iPhone/Pod. The framework is just great, but I fail at touch detection. I read that you just need to overwrite the proper functions (e.g. "touchesBegan" ) in the implementation of a class which subclasses CocosNode. But it doesn't work. What could I do wrong?

                  功能:

                  -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{NSLog(@"tickle, hihi!");}
                  

                  我完全搞错了吗?

                  推荐答案

                  Layer 是 cocos2d 中唯一接触到的类.

                  Layer is the only cocos2d class which gets touches.

                  诀窍是 Layer 的所有实例一个接一个地传递触摸事件,所以你的代码必须处理这个.

                  The trick is that ALL instances of Layer get passed the touch events, one after the other, so your code has to handle this.

                  我是这样做的:

                  -(BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
                  UITouch *touch = [touches anyObject];
                  CGPoint location = [touch locationInView: [touch view]];
                  CGPoint cLoc = [[Director sharedDirector] convertCoordinate: location];
                  
                  float labelX = self.position.x - HALF_WIDTH;
                  float labelY = self.position.y - HALF_WIDTH;
                  float labelXWidth = labelX + WIDTH;
                  float labelYHeight = labelY + WIDTH;
                  
                  if( labelX < cLoc.x &&
                      labelY < cLoc.y &&
                      labelXWidth > cLoc.x &&
                      labelYHeight > cLoc.y){
                          NSLog(@"WE ARE TOUCHED AND I AM A %@", self.labelString);
                          return kEventHandled;
                      } else {
                          return kEventIgnored;
                      }
                  

                  }

                  请注意,cocos2d 库有一个ccTouchesEnded"实现,而不是 Apple 标准.它允许您返回一个 BOOL 指示您是否处理了事件.

                  Note that the cocos2d library has a "ccTouchesEnded" implementation, rather than the Apple standard. It allows you to return a BOOL indicating whether or not you handled the event.

                  祝你好运!

                  这篇关于cocos2D for iPhone 和触摸检测的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:cocos2d游戏中如何实现暂停/恢复? 下一篇:如何让对象对 Cocos2D 中的触摸做出反应?

                  相关文章

                1. <small id='Esvy6'></small><noframes id='Esvy6'>

                  <i id='Esvy6'><tr id='Esvy6'><dt id='Esvy6'><q id='Esvy6'><span id='Esvy6'><b id='Esvy6'><form id='Esvy6'><ins id='Esvy6'></ins><ul id='Esvy6'></ul><sub id='Esvy6'></sub></form><legend id='Esvy6'></legend><bdo id='Esvy6'><pre id='Esvy6'><center id='Esvy6'></center></pre></bdo></b><th id='Esvy6'></th></span></q></dt></tr></i><div id='Esvy6'><tfoot id='Esvy6'></tfoot><dl id='Esvy6'><fieldset id='Esvy6'></fieldset></dl></div>

                        <bdo id='Esvy6'></bdo><ul id='Esvy6'></ul>

                      <legend id='Esvy6'><style id='Esvy6'><dir id='Esvy6'><q id='Esvy6'></q></dir></style></legend>
                    1. <tfoot id='Esvy6'></tfoot>