我的场景中有7个精灵。所有的精灵都加入了mutablearray。当我触摸一个精灵移动时,其他精灵在触摸移动方法后不可见
这是我的代码
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;
}
我的touchesmove方法:
-(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);
}
}
答案 0 :(得分:1)
您似乎将所有精灵位置设置为与触摸位置相同。这意味着除了最顶层的精灵之外,所有精灵都被掩盖了......
for(CCSprite *s in sprites)
{
s.position=ccp(location.x,location.y);
}