2012-03-30 49 views
0

我正在寫瓦片基礎遊戲,並且在將瓦片紋理和紋理構建到屏幕上之後,幀速率從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]; 

但他們不提高性能在所有。還有什麼我可以做的嗎?

在此先感謝。

亞歷

+0

如果你說什麼操作系統版本和你使用的是什麼設備,它可能會幫助人們幫助你。 – ader 2012-03-30 09:12:27

回答

1

你說:

後google搜索和嘗試不同的解決方案的日子...

what have you tried?


嘗試把所有的精靈那是在中使用相同的紋理。這使得這些精靈只需要一個glBindTexture調用就可以呈現,這個調用非常緩慢。

CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"Icon-72.png"]; 
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); 
     [batchNode addChild:vlo_Temp[vli_Counter]]; 
    } 

[self addChild batchNode]; 
+0

感謝James,在我的程序中,我在各個文件中都有精靈,在過去的幾天裏,我將其更改爲精靈表,並且嘗試了像[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA4444]這樣的設置;如果(![CCDirector setDirectorType:kCCDirectorTypeDisplayLink]) [CCDirector setDirectorType:kCCDirectorTypeMainLoop]; – dimsumz 2012-03-30 10:15:15

+0

將所有精靈添加到該spritesheet並使用spritesheet紋理作爲batchnode的參數。 – 2012-03-30 10:16:05

+0

謝謝,我將給批處理節點一個去:) – dimsumz 2012-03-30 10:17:16

0

說到性能......你有沒有試過在設備上運行?模擬器的實際「iSomething」性能很差,特別是在處理高清圖片和衆多精靈時。