【发布时间】:2012-03-30 07:43:31
【问题描述】:
我正在编写一个瓷砖基础游戏,在我将瓷砖纹理和构建纹理加载到屏幕上后,我的帧速率从 60 下降到了 30。经过几天的谷歌搜索和尝试不同的解决方案,我仍然无法找出原因。
隔离和理解问题。我创建了一个简单的项目,它在加载程序时在随机位置显示 100 个精灵,之后在 HellowWorld 层中什么也不做:
// on "init" you need to initialize your instance
-(id) init
{
if( (self=[super init])) {
CCTexture2D *vlo_Texture = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:@"Icon-72.png"]];
CCSprite *vlo_Temp[100];
NSInteger vli_X, vli_Y;
for (NSInteger vli_Counter=0; vli_Counter<100; vli_Counter++)
{
vli_X = arc4random()%480;
vli_Y = arc4random()%320;
vlo_Temp[vli_Counter] = [CCSprite spriteWithTexture:vlo_Texture]; //[CCSprite spriteWithFile:@"Icon-72.png"];
vlo_Temp[vli_Counter].position = ccp(vli_X, vli_Y);
[self addChild:vlo_Temp[vli_Counter]];
}
}
return self;
}
上面的代码只运行 30fps 的事实让我很震惊。我没有计时器来刷新这些精灵。我相信系统应该只绘制所有精灵并且什么都不做(我假设?)
我曾尝试申请:
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA4444];
和
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
[CCDirector setDirectorType:kCCDirectorTypeMainLoop];
但是它们根本没有提高性能。还有什么我可以做的吗?
提前致谢。
亚历克斯
【问题讨论】:
-
如果您说出您使用的操作系统版本和设备,它可能会帮助人们帮助您。
标签: iphone performance graphics cocos2d-iphone frame-rate