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

      • <bdo id='CWjqP'></bdo><ul id='CWjqP'></ul>
      1. <small id='CWjqP'></small><noframes id='CWjqP'>

        在 COCOS2D 中移动的触摸上画线

        时间:2024-04-14
        <legend id='gJD0S'><style id='gJD0S'><dir id='gJD0S'><q id='gJD0S'></q></dir></style></legend>
        <i id='gJD0S'><tr id='gJD0S'><dt id='gJD0S'><q id='gJD0S'><span id='gJD0S'><b id='gJD0S'><form id='gJD0S'><ins id='gJD0S'></ins><ul id='gJD0S'></ul><sub id='gJD0S'></sub></form><legend id='gJD0S'></legend><bdo id='gJD0S'><pre id='gJD0S'><center id='gJD0S'></center></pre></bdo></b><th id='gJD0S'></th></span></q></dt></tr></i><div id='gJD0S'><tfoot id='gJD0S'></tfoot><dl id='gJD0S'><fieldset id='gJD0S'></fieldset></dl></div>
              <tfoot id='gJD0S'></tfoot>
                <bdo id='gJD0S'></bdo><ul id='gJD0S'></ul>

              • <small id='gJD0S'></small><noframes id='gJD0S'>

                    <tbody id='gJD0S'></tbody>
                  本文介绍了在 COCOS2D 中移动的触摸上画线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 COCOS2D 为 iPhone 开发游戏.

                  I'm developing a game for iPhone using COCOS2D.

                  其中,当用户将手指从一个点拖动到另一个点时,我需要画一条线.据我所知,我需要在 Touches Moved method 中执行此操作,我可以从中获得积分.

                  In that, I need to draw a line when user drag his finger from a point to another. As far as my knowledge is concern I need to do this in Touches Moved method from where I can get the points.

                  但我不知道该怎么做.有人可以帮我解决这个问题吗?

                  But I don't know how to do this. Can anybody help me on this?

                  推荐答案

                  起亚ora.无聊迫使我就这个话题提供答案.

                  Kia ora. Boredom compels me to provide an answer on this topic.

                  图层部分(即@interface GetMyTouches : CCLayer):

                  Layer part (i.e. @interface GetMyTouches : CCLayer):

                  -(void) ccTouchesMoved:(NSSet *)inappropriateTouches withEvent:(UIEvent *)event
                  {
                      UITouch *touchMyMinge = [inappropriateTouches anyObject];
                  
                      CGPoint currentTouchArea = [touchMyMinge locationInView:[touchMyminge view] ];
                      CGPoint lastTouchArea = [touchMyMinge previousLocationInView:[touchMyMinge view]];
                  
                      // flip belly up. no one likes being entered from behind.
                      currentTouchArea = [[CCDirector sharedDirector] convertToGL:currentTouchArea];
                      lastTouchArea = [[CCDirector sharedDirector] convertToGL:lastTouchArea];
                  
                      // throw to console my inappropriate touches
                      NSLog(@"current x=%2f,y=%2f",currentTouchArea.x, currentTouchArea.y);
                      NSLog(@"last x=%2f,y=%2f",lastTouchArea.x, lastTouchArea.y);  
                  
                     // add my touches to the naughty touch array 
                     naughtyTouchArray addObject:NSStringFromCGPoint(currentTouchArea)];
                     naughtyTouchArray addObject:NSStringFromCGPoint(lastTouchArea)];
                  }
                  

                  节点部分(即@interface DrawMyTouch:CCNode):

                  Node part (i.e. @interface DrawMyTouch: CCNode) :

                  @implementation DrawMyTouch
                  
                  -(id) init
                  {
                      if( (self=[super init])) 
                      { }
                      return self;
                  }
                  
                  -(void)draw
                  {
                      glEnable(GL_LINE_SMOOTH);
                  
                      for(int i = 0; i < [naughtyTouchArray count]; i+=2)
                      {
                          start = CGPointFromString([naughtyTouchArray objectAtIndex:i]);
                          end = CGPointFromString([naughtyTouchArray objectAtIndex:i+1]);
                  
                          ccDrawLine(start, end);
                      }
                  }
                  
                  @end
                  

                  第二部分(即@interface GetMyTouches : CCLayer):

                  Layer part II (i.e. @interface GetMyTouches : CCLayer):

                  -(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
                  {   
                      DrawMyTouch *line = [DrawMyTouch node];
                      [self addChild: line];
                  }
                  

                  记住触摸很容易.触摸时知道自己在做什么不是火箭科学.

                  Remember touching is easy. Knowing what you're doing while touching isn't rocket science.

                  最后,如果你不明白我发布的任何内容......请选择烘焙.世界需要更多的巧克力蛋糕生产商.

                  Finally, if you don't understand anything i've posted ... take up baking. The world needs more chocolate cake producers.

                  澄清:

                  1. 没有人能从 cut 'n paste 中学到东西~这个 代码 从来没有打算在没有爱抚的情况下工作
                  2. 如果你看不到幽默,那你就错了职业
                  1. No one learns from cut 'n paste ~ this code was never meant to work without caressing
                  2. If you fail to see the humour, you're in the wrong profession

                  值得注意的是,我喜欢美味的巧克力蛋糕.世界确实需要更多出色的面包师.这不是侮辱,是鼓励.

                  Of note, I love a good chocolate cake. The world really does need more fantastic bakers. That's not an insult, that's encouragement.

                  看看广场外面,找到一个充满知识的圆圈,让生活变得有价值"~Aenesidemus.

                  这篇关于在 COCOS2D 中移动的触摸上画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:cocos2d iphone 5 4 英寸显示器支持 下一篇:如何卸载 cocos2d 模板?

                  相关文章

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

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