My hands on example is:
I've got a large "map", background of the whole game level. I build it up from background tiles drawing on a Bitmap through a Canvas:
Using java Syntax Highlighting
- bgImage = Bitmap.createBitmap(lvl.baseMap[0].length*frameW, lvl.baseMap.length, Bitmap.Config.ARGB_8888);
- Canvas canvas = new Canvas(bgImage);
- for (int i = 0; i < lvl.baseMap.length; i++)
- {
- y = i * tileH;
- for (int j = 0; j < lvl.baseMap[i].length; j++)
- {
- x = j * tileW;
- type = lvl.baseMap[i][j];
- canvas.drawBitmap(bgTilesBitmap,
- bgTileData[type].srcRect,
- new Rect (x, y, x + bgTileData[type].width, y + bgTileData[type].height),
- null);
- }
- }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
The whole thing is persistent during the game so drawing every tile individually seems like a big waste, so I figure this way is a sane route to walk down. This large bitmap gives me a bit of headache though:
1. It's very likely to not be a POW 2, can I still load it up with GLUtils.texImage2D?
2. How to only draw the visible part of it? What I've tried (with small images only) is to load them into IntBuffers, together with an Intbuffer of squares then do
[syntax="java"]
gl.glVertexPointer(2, GL10.GL_FIXED, 0, mVertexBuffer);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, mTextureBuffer);
gl.glColor4f(1, 1, 1, 1);
for (int i = 0; i < yTiles*xTiles*8; i += 4) // 8 being 4 pairs of x,y for a square
{
gl.glNormal3f(0, 0, 0);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, i, 4);
}
If the vertexes are larger than the texture will it stretch, and shrink the texture if it's small. I suppose this will be the case with my map too? If I make a square covering the full screen will it shrink my map to fit, how to prevent that?
3. In general, is it possible and practical to have several layers on the screen? In my case am I thinking one for the map, which only changes if there is a scroll event, one which I draw sprites of the player/other things moving around (updated very often) and one with explosions. In my mind would that make things more optimized, I'd only need to redraw the layer having a change. My plan was to have the game 3D with background furthest back and only clear the depth of what's needed. Or is this just wishful thinking?
Sorry for the length and I'd really appreciate if someone could shed some light on these problems for me.


