我有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 (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;
}
@ LearnCocos2D:我总是想知道:什么是CCArray对于无论如何都有用?我从来没有使用它(只有NSMutableArray) – Voldemort 2012-08-13 20:51:45
@ LearnCocos2D感谢它的工作正常,感谢您的帮助! – Paul 2012-08-16 07:14:11