我正在寫瓦片基礎遊戲,並且在將瓦片紋理和紋理構建到屏幕上之後,幀速率從60下降到了30。經過數天的搜索和嘗試不同的解決方案後,我仍然無法找出原因。簡單代碼上的Cocos2d性能問題
分離並理解問題。我已經創建了一個簡單的項目,它在任意位置顯示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];
但他們不提高性能在所有。還有什麼我可以做的嗎?
在此先感謝。
亞歷
如果你說什麼操作系統版本和你使用的是什麼設備,它可能會幫助人們幫助你。 – ader 2012-03-30 09:12:27