所以我正在制作一个儿童游戏,如下所示:
我有大约 118 个不同的CENTER_OBJECTS,如 Apple、Ball、Cat 等,它们将被放置在中心并且ALPHABETS围绕它旋转,因此当您单击正确的字母时,您会移动并替换CENTER_OBJECT。
我面临的问题是,当 CENTER_OBJECT 的显示框架被替换时,我观察到正在移动的字母略有滞后。我很确定这是由于将显示框架设置为 new word 引起的。
我正在为每个CENTER_OBJECT 异步缓存Sprite 表。那么有什么方法可以建议您停止这种轻微的滞后吗?
编辑
好吧,在播放器开始播放之前,我会缓存 5 个中心对象,当只剩下 2 个缓存对象时,我开始缓存接下来的 5 个项目。所以我有一个功能:
-(void)getNext5RandomsForHalf:(NSInteger)half{
int i;
// half is just a way to preload , alternatively 1st half
// or 2nd half is used for cached Center Objects
if (half==0) {
i=0;
}else
{
i=5;
}
for (int j=0; j<5; j++) {
NSInteger objectIndex;
do {
objectIndex=(arc4random()%[self.centerObjects count]);
} while (playedObjects[objectIndex]==1);
playedObjects[objectIndex]=1;
batchRandomObjects[j+i]=objectIndex; // this is used to store precalculated
//random numbers
NSString *tempString = (NSString*)[self.centerObjects objectAtIndex:j];
NSString *filename = [NSString stringWithFormat:@"%@.plist",tempString];
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:filename];
CCLOG(@"%@ file added",filename);
}
dispatch_async( dispatch_get_main_queue(), ^{
// Code for Starting the play for the first time .
if (justStarted) {
[self playForNextObjectWithNumberOfLetters:self.numberOfLetters];
justStarted=NO;
}
});
});
}
在我的 playForNextObjectWithNumberOfLetters: 中,我声明并初始化了游戏对象:CenterObject,并相应地设置了它的显示框架。所以我有一个名为 NSString* centerObjectName 的属性,它被我覆盖以用于显示框架
-(void)setCenterObjectName:(NSString*)name
{
_centerObjectName = [name retain];
CCSpriteFrame* frame = [[CCSpriteFrameCache
sharedSpriteFrameCache]spriteFrameByName:_centerObjectName];
self.displayFrame = frame;
}