English 中文(简体)
低效与开放式GL和GLKit的游戏
原标题:Low performance with tiles-based game with OpenGL and GLKit

与GLKit一道使用开放式的GL,以形成一种无益的游戏。 在比赛中,约有1024个tile子被放置在屏幕上,问题在于,每刻我一把tile子变成tile。 盲人被叫到,我一度丧失了业绩。

这就是我如何做的(阵列是静态的,芭蕾舞团正在环绕屏幕上移动):

- (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];
    }
}

正如我说过的那样,帆风顺在屏幕上是静态的,但芭蕾舞团正在快车旁(每处更新一次)。 如果我只打上球,那么它就会非常快,如果我增加空子,它就会非常缓慢(只用模拟器进行审判)。

This is how I render:

- (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);

}
最佳回答

我确定,它缩小了碎片使用的图像的规模,并提出了具体框架。

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签