与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);
}