2012-04-10 14 views
0

OpenGL with GLKitを使ってタイルベースのゲームを作っています。ゲームでは1024タイルが画面に表示されますが、drawInRectが呼び出されるたびにタイルをレンダリングしているため、パフォーマンスが非常に低下しています。 tilesArrayが画面で静的で、OpenGLとGLKitを使ったタイルベースのゲームでパフォーマンスが低い

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect 
{ 
    glClearColor(1, 1, 1, 1); 
    glClear(GL_COLOR_BUFFER_BIT);  
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
    glEnable(GL_BLEND); 


    for (int i = 0; i < [self.tilesArray count]; i++){    
     RPSprite *tempTile = [self.tilesArray objectAtIndex:i]; 
     [tempTile render]; 
    } 


    for (RPSprite *ball in self.ballsArray){ 
     [ball render]; 
    } 
} 

私が言ったように、しかしballsArrayは(非常に高速な画面の周りに動いている:

これは私がレンダリングする方法である(tilesArrayはballsArrayは、画面の周りに移動し、静的です)更新ごとに)。私はボールを入れた場合、それは私がタイルを追加する場合、それは(のみシミュレータで試してみました)非常に遅くなると、非常に高速になり

これは私がレンダリング方法です:

- (GLKMatrix4) modelMatrix { 

    GLKMatrix4 modelMatrix = GLKMatrix4Identity; 
    modelMatrix = GLKMatrix4Translate(modelMatrix, self.position.x,320 - self.position.y - self.textureInfo.height, 0); 
    return modelMatrix; 

} 

- (void)render { 

    self.effect.texture2d0.name = self.textureInfo.name; 
    self.effect.texture2d0.enabled = YES; 
    self.effect.transform.modelviewMatrix = self.modelMatrix; 

    [self.effect prepareToDraw]; 

    long offset = (long)&_quad; 

    glEnableVertexAttribArray(GLKVertexAttribPosition); 
    glEnableVertexAttribArray(GLKVertexAttribTexCoord0); 

    glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void *) (offset + offsetof(TexturedVertex, geometryVertex))); 
    glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void *) (offset + offsetof(TexturedVertex, textureVertex))); 

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

} 
+3

タイルをテクスチャにレンダリングしてから1クワッドを描画してみませんか?あなたのレジャーでテクスチャのタイルを更新してください。 – Robinson

+1

[Cocos2DからCCTMXTiledMap](https://github.com/cocos2d/cocos2d-iphone/blob/gles20/cocos2d/CCTMXLayer.m)または実験を見てみましょう[Cocos2D拡張子:HKTMXTiledMap](https://でgithubの.com/ricardoquesada/cocos2d-iphone-extensions/tree/gles20-hktmx/Extensions/HKTMXTiledMap)アイデアのために! – MechEthan

+0

ありがとう@ロビンソン、良いアイデア、あなたはそれを行う方法をより具体的にすることができますか?あなたがそれを答えに入れるなら、私は受け入れます。 –

答えて

0

私はそれが縮小固定タイルによって使用される画像のサイズ、および特定のフレームレートを表示することができます。

関連する問題