Following this: The best approach to playing the oldschool tree game 2D
I have a simple 2D tile generator that works, im reading an int [100] [100] card filled with 1 or 0 and draw the tiles according to their tile id, 0 is water, 1 grass.
Im using some basic Numpad control handler using camIncr (32.0f), I set the camera position according to the movement:
case KeyEvent.KEYCODE_DPAD_RIGHT:
cameraPosX = (float)(cameraPosX + camIncr);
break;
In my drawing loop im just draw enough tiles to fit on my screen and trace the top left tile using cameraOffsetX and cameraOffsetY (its camera position / tile size)
Im using GLU.gluOrtho2D for my projection.
Here is a drawing loop inside my own renderer:
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode( GL10.GL_PROJECTION );
gl.glLoadIdentity( );
GLU.gluOrtho2D(gl, 0, scrWidth, scrHeight, 0);
repere.draw(gl, 100.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
tiledBackground.draw(gl, filtering);
my tiledBackground :
int cols = (569 / 32) + 2;
int rows = (320 / 32) + 1;
int cameraPosX = (int) Open2DRenderer.getCameraPosX();
int cameraPosY = (int) Open2DRenderer.getCameraPosY();
tileOffsetX = (int) (cameraPosX / 32);
tileOffsetY = (int) (cameraPosY / -32);
gl.glPushMatrix();
for (int y = 0; y < rows; y++) {
for (int x = 0; x < cols; x++) {
try {
tile = map[y + tileOffsetY][x + tileOffsetX];
} catch (Exception e) {
e.printStackTrace();
tile = 0;
}
gl.glPushMatrix();
if (tile==0){
waterTile.draw(gl, filter);
}
if (tile==4) {
grassTile.draw(gl, filter);
}
gl.glTranslatef(32.0f, 0.0f, 0.0f);
}
gl.glPopMatrix();
gl.glTranslatef(0.0f, 32.0f, 0.0f);
}
gl.glPopMatrix();
}
waterTile grassTile.draw 32x32, , .
, numpad, "" , im , , (. android OpenGL ES simple , "" )
, " ". camIncr, GLU.gluOrtho2D .., .
?:)