Objective c 如何避免图像重复时出现时间延迟?

Objective c 如何避免图像重复时出现时间延迟?,objective-c,cocos2d-iphone,nsmutablearray,ccsprite,repeat,Objective C,Cocos2d Iphone,Nsmutablearray,Ccsprite,Repeat,我有3张图片,我想一张接一张地重复它们。当层向左移动时,第一个图像将不再可见,并且该图像将在右侧最后一个图像之后的新位置上显示,因此第一个图像将成为第三个图像,并重复动画 我的问题是,有时会有一点时间延迟,我认为当第一个图像被删除并放到第三个位置时会发生这种情况。我们几乎没有注意到,但这是一种“暂停”动画0.1秒,我想避免这种情况 你知道怎么做吗?我尝试过使用此代码(删除图像并再次插入),或者只是用replace…atIndex替换,但我遇到了同样的问题。代码是: if (offsetParam

我有3张图片,我想一张接一张地重复它们。当层向左移动时,第一个图像将不再可见,并且该图像将在右侧最后一个图像之后的新位置上显示,因此第一个图像将成为第三个图像,并重复动画

我的问题是,有时会有一点时间延迟,我认为当第一个图像被删除并放到第三个位置时会发生这种情况。我们几乎没有注意到,但这是一种“暂停”动画0.1秒,我想避免这种情况

你知道怎么做吗?我尝试过使用此代码(删除图像并再次插入),或者只是用
replace…atIndex
替换,但我遇到了同样的问题。代码是:

if (offsetParam <= offset1-spriteWidth){
        CCSprite *temp = [[sprites objectAtIndex:0] retain];
        [sprites removeObjectAtIndex:0];
        [sprites addObject:temp];
        temp.position = ccp(-offset1+(2*spriteWidth), temp.position.y);
        [temp release];

        offset1 -= spriteWidth;
 }
if(offsetParam 2)counterGrass=0;
温度位置=ccp(偏移量1+(2*spriteWidth),温度位置y)//不起作用
[临时释放];
偏移量1-=精灵宽度;
}
是CCArray类型还是NSMutableArray类型的“精灵”?因为CCArray在removeObjectAtIndex方面存在严重的性能问题,特别是在索引较低(在数组的开头)的情况下(如您的情况)

您可以尝试切换到NSMutableArray,看看是否有帮助


或者,避免使用remove和add,因为这是多余的。而是使用一个索引计数器,告诉您哪个数组索引是第一个精灵。当索引>=精灵数组中的项数时,将其重置为0。

@learncos2D:我一直在想:CCArray到底有什么用?我从未使用过它(仅NSMutableArray)
if (rightDirection){
    //RIGHT
    CCLOG(@"offsetParam %f, offset1-spriteWidth %f", offsetParam, offset1-spriteWidth);
    if (offsetParam < offset1-spriteWidth){ //move the block to the right

        CCSprite *temp = [[grasses objectAtIndex:counterGrass] retain];
        counterGrass++;
        if (counterGrass>2) counterGrass = 0;
        temp.position = ccp(offset1+(2*spriteWidth), temp.position.y);//does not work
        [temp release];
        offset1 -= spriteWidth;
    }