0

重複の可能性:
1 つのスプライトを移動している間、すべてのスプライトが表示されない

シーンに 7 つのスプライトがあります。すべてのスプライトが mutablearray に追加されます。1 つのスプライトをタッチして移動すると、他のスプライトがタッチ後に表示されない

ここに私のコードがあります

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;
}

私のタッチムーブ方法:

-(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);
}
}
4

1 に答える 1

1

すべてのスプライト位置をタッチ位置と同じに設定しているようです。これは、一番上のスプライトを除くすべてのスプライトが覆われていることを意味します...

for(CCSprite *s in sprites)
{
   s.position=ccp(location.x,location.y);
}
于 2013-01-28T09:50:38.510 に答える