<tfoot id='601tX'></tfoot>
      1. <legend id='601tX'><style id='601tX'><dir id='601tX'><q id='601tX'></q></dir></style></legend>
        • <bdo id='601tX'></bdo><ul id='601tX'></ul>

        <small id='601tX'></small><noframes id='601tX'>

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

        移动一个精灵时所有精灵不可见

        时间:2024-08-12

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

          <legend id='2zQxi'><style id='2zQxi'><dir id='2zQxi'><q id='2zQxi'></q></dir></style></legend>
            <tbody id='2zQxi'></tbody>
            <bdo id='2zQxi'></bdo><ul id='2zQxi'></ul>

            <tfoot id='2zQxi'></tfoot>

                  <small id='2zQxi'></small><noframes id='2zQxi'>

                  本文介绍了移动一个精灵时所有精灵不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的场景中有 7 个精灵.所有的精灵都添加到 mutablearray.当我触摸一个精灵移动时,其他精灵在我触摸移动方法后不可见

                  I am having 7 sprites in my scene.All the sprites are add to mutablearray. when i touch one sprite to move,other sprites not visible after my touches move method

                  这是我的代码

                  if( (self=[super init])) {
                  
                  sprites=[[NSMutableArray alloc]init];
                  
                  CCLayer *base=[CCSprite spriteWithFile:@"Base.png"];
                  base.position=ccp(512,384);
                  [self addChild:base];
                  
                   x=0;
                   for(int i=1;i<=7;i++)
                   {
                      CCSprite *hole=[CCSprite spriteWithFile:@"ball.png"];
                      hole.position=ccp(140+x,318);
                      hole.tag=i;
                   [self addChild:hole];
                      hole.visible=YES;
                      [sprites addObject:hole];
                      x=x+75;
                   }
                  
                  self.isTouchEnabled=YES;
                  
                  }
                  return self;
                  }
                  
                  
                  My touchesmove method:
                  
                  
                  
                  -(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
                  {
                  NSLog(@"count:%i",[sprites count]);
                  UITouch *touch=[touches anyObject];
                  CGPoint location=[touch locationInView:[touch view]];
                  location=[[CCDirector sharedDirector]convertToGL:location];
                  location=[self convertToNodeSpace:location];
                  
                  for(CCSprite *s in sprites)
                  {
                  s.position=ccp(location.x,location.y);
                  }
                  }
                  

                  推荐答案

                  在您的 ccTouchesMoved 方法中,您正在 moving 替换 (1)你所有的精灵一起在行中:

                  In your ccTouchesMoved method, you are moving replacing (1) all your sprites together in the lines:

                  for(CCSprite *s in sprites)
                  {
                      s.position=ccp(location.x,location.y);
                  }
                  

                  另外,我认为你的精灵都是相同的大小,所以你无法区分它是一个精灵还是更多.

                  In addition, I think your sprites are all of the same size so you are unable to differentiate whether it is one sprite or more.

                  在你的 init 方法中,你应该为每个精灵提供一个标签,然后通过它的 tag 在 ccTouchesMoved 方法中.

                  In your init method, you should provide a tag to each sprite, and then modify it by its tag in the ccTouchesMoved method.

                  在该方法中,您应该知道正在触摸哪个精灵,然后采取相应的行动.尝试在 location 周围定义一个矩形.类似于 这个.

                  In that method, you should know which sprite is being touched, and then act accordingly. Try defining a rectangle around location. Something like this.

                  当多个精灵被触摸时,您可能需要做一些事情.最常见的做法是对顶部的精灵执行操作(z)或由精灵tags 决定.

                  You might have to do something for the case when multiple sprites being touched. The most common thing to do is to perform actions on the sprite at the top (z) or decide by sprite tags.

                  (1) 要将精灵移动到某个位置,您应该使用一些 CCAction,很可能是 CCMoveTo 并且在某些情况下 CCMoveBy.

                  (1) To move your sprite(s) to some location, you should be using some CCAction, most likely CCMoveTo and in some cases CCMoveBy.

                  这篇关于移动一个精灵时所有精灵不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何将 CCSpriteFrame 转换为 CCTexture2D (Cocos2d) 下一篇:cocos2d:在菜单背景下播放视频

                  相关文章

                  <tfoot id='5rHxo'></tfoot>

                    1. <small id='5rHxo'></small><noframes id='5rHxo'>

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

                        <bdo id='5rHxo'></bdo><ul id='5rHxo'></ul>
                      <legend id='5rHxo'><style id='5rHxo'><dir id='5rHxo'><q id='5rHxo'></q></dir></style></legend>