(2D Only) Tiling screen
Blitz3D Forums/Blitz3D Programming/(2D Only) Tiling screen
| ||
Hi all. Here's my problem: I have an array, tileArray(i, j). Each array element contains a 16 x 16 tile. I have drawn them to the screen to map over the entire screen: for i = 0 to 63 for j = 0 to 47 drawImage tileArray(i, j), 16 * i, 16 * j next next The problem is, performing this many draw operations in a single program loop is WAY too cpu intensive. Does anyone have an idea of a faster method? It's important that the tiles can be updated on a frame-by-frame basism because some of the tiles are animated. Thanks a lot. |
| ||
If you can, try using bigger tiles - 32x32 minimum. Also, try using DrawBlock instead of DrawImage. That may speed things up a tad. |
| ||
Thanks for the reply, big10p. Unfortunately, using larger tiles is not possible - they're as big as they can be already. The suggestion of using drawblock DID speed things up, but not enough; real time drawing of the tiles each loop now runs at about half the required speed (60 fps), which is an improvement. Any suggestions of algorithm changes? If you needed to tile the screen with an array of different 16x16 tiles as quickly as possible, how yould you do it? |
| ||
If you needed to tile the screen with an array of different 16x16 tiles as quickly as possible, how yould you do it? I'd probably use a 2D-in-3D system, TBH. Pure 2D just seems to be too slow with tiles this small, especially as newer GFX cards don't handle pure 2D drawing very well at all, so I'm told.I guess you could try and implement some kind of 'dirty rects' system, where only the parts of the screen that change between frames are actually re-drawn, but that would be too much hassle for me, personally. Someone will probably be along in a minute, recommending you get BlitzMax, as it'll handle this situation far better. :) |
| ||
I'm doing a tiled game (64x64) with several layers. I'm using Sprite Candy and up to now the performance are very good (>100 FPS) so maybe it could be a good way to investigate. |
| ||
You could try this... At start of level: 1. DrawBlock all tiles 2. GrabImage the whole screen In main loop: 1. DrawBlock grabbed image 2. DrawBlock animated tiles only Blitz is pretty fast at drawing large images - and the fact you'd only be drawing the animated tiles every frame should give you an increased framerate (assuming not every tile is animated, of course!). |
| ||
If lots of the tiles are animating then there's no good way to optimise it, youll probably have to just keep drawing every tile. The one alternative you have is to find the render to texture addon from indiepath and use alternate render buffers. |