I''m trying to make a simple tile engine for my 2d game. Just as a moving background. I use tiles that are 16x16 pixels. After some testing I found out that blitting these every "frame" was really slowing down. How can I get it faster? Any small tileengines for download somewhere?
You should make sure that you are only drawing the tiles that are currently on screen. Are you using DirectX to draw the tiles? Make sure you are using a back buffer. Blitting all tiles at once should be pretty fast (its just copying bits of memory around).
- Daniel
VG Games
- Daniel
VG Games
- DanielMy homepage
Yeah, if you are using DirectX, make sure your surfaces are all in video memory or else it WILL slow down a lot! Not sure about in dos....
quote: I'm trying to make a simple tile engine for my 2d game. Just as a moving background. I use tiles that are 16x16 pixels. After some testing I found out that blitting these every "frame" was really slowing down. How can I get it faster? Any small tileengines for download somewhere?
If you are looping thru' your map each frame and copying the
tiles one at a time to the buffer, ie something like this:
for (i=0;i for (j=0;j DrawABloodyTileAlready(j*16,i*16,Tiles[Map [j]]);
then no matter where you load your tiles, it is going to be
ridiculously slow because it is calling the blitter 50 billion
times.
One answer: Pre-generate!!
If your map is small enough, then you just have a BIG surface
with all the tiles already copied onto it at load time.
Then in your game loop you do 1 blit, just copy the visible
portion to the backbuffer.
Of course, if you're ambitious (like you should be), then you're
going to have big humoungous maps that you couldn't possibly
completely pre-generate, so instead generate 3-4 screens surrounding the player, and when he/she/it reaches an edge screen, generate the NEW 3-4 screens.
//This is an example code segment only. It is just to//give the idea. //define the size of our generated map segment#define TilesWide 1000#define TilesHigh 1000#define ScreenWidth 640#define ScreenHeight 480//These are a few surfaces//Note: Temp should be created with a size that is// TilesWide * 16 wide, and TilesHigh * 16 high.LPDIRECTDRAWSURFACE7 Primary, //The screen buffer Back, //The back buffer Temp, //the generated segment Tiles[255]; //the actual tilesint map[20000][20000]; //A suitably ambitous map sizeint PlayerTileX,PlayerTileY; //Where the player is in map termsint TempCenterX,TempCenterY; //Where our generated map is // centered.//GenerateTemp builds the segment AROUND (TileX,TileY)//This example doesn't check for invalid tiles (ie://negative indexes).void GenerateTemp(int TileX,int TileY){ int i,j,n = 0,m = 0; TempCenterX = TileX; TempCenterY = TileY; for (i=TileY - (TilesHigh / 2);i < TileY + (TilesHigh / 2);i++) { for (j=TileX - (TilesWide/2);j < TileX + (TilesWide / 2);j++) { YourBlitRoutineHere(Tiles[map<i>[j]],Temp,16*m,16*n); m++; } n++; }}void ExampleGameLoop(){ GetInputFromPlayer(); MoveYourPlayerAround(); MoveYourBaddiesAround(); //Are we at an edge yet? if so, the re-generate if (PlayerTileX - TempCenterX > TilesWide / 2 || PlayerTileX - TempCenterX < - (TilesWide / 2) || PlayerTileY - TempCenterY > TilesHigh / 2 || PlayerTileY - TempCenterY < - (TilesHigh / 2)) { GenerateTemp(PlayerTileX,PlayerTileY); } DrawAllYourPicturesToBackBufferNow();}
Anyways, I hope that gave you a few (good) ideas. I could be
wrong though, I haven't tested any of this stuff yet.
----------
Disco Love For Everyone
Edited by - SpazBoy_the_Mitey on August 22, 2000 11:31:16 PM
Edited by - SpazBoy_the_Mitey on August 22, 2000 11:32:35 PM
Edited by - SpazBoy_the_Mitey on August 22, 2000 11:34:32 PM
----------"i think that all this talking and such is paining my head to astounding annoyance" - Erick"Quoting people in your tag is cool. Quoting yourself is even cooler" - SpazBoy_the_MiteyDisco Love For Everyone
Wow... if 20000x20000 is only "suitably ambitious" then I''m pretty pathetic.
In any case, that will work, but you''re going to lose out on a few things. For one thing, pre-generated screen images can''t have tile animations unless you want to change the images every frame, which pretty much defeats the purpose of having pre-generated images. Also, you won''t be able to have layers of tiles that are plotted after the characters, to add depth. Unless of course you have two pre-generated images for each screen: background and foreground. And that doubles the memory that''s required.
Just out of curiosity, what resolution are you running in? I wrote a very simple tile engine for DirectX that redraws three layers of 16x16 tiles every frame, and it runs very quickly in 320x240x16bpp. That''s about as low-res as it gets, but with a tile size like 16x16, you can''t be running much higher than 640x480, right?
-Ironblayde
Aeon Software
In any case, that will work, but you''re going to lose out on a few things. For one thing, pre-generated screen images can''t have tile animations unless you want to change the images every frame, which pretty much defeats the purpose of having pre-generated images. Also, you won''t be able to have layers of tiles that are plotted after the characters, to add depth. Unless of course you have two pre-generated images for each screen: background and foreground. And that doubles the memory that''s required.
Just out of curiosity, what resolution are you running in? I wrote a very simple tile engine for DirectX that redraws three layers of 16x16 tiles every frame, and it runs very quickly in 320x240x16bpp. That''s about as low-res as it gets, but with a tile size like 16x16, you can''t be running much higher than 640x480, right?
-Ironblayde
Aeon Software
"Your superior intellect is no match for our puny weapons!"
good points there Ironblayde, everything I''m working on at
the moment is for a top-down shoot ''em up (see rayden fighters,
raptor, etc) and the backgrounds in those games are mostly static. So I''ve sort of let this bias my answer.
I once coded a little dungeon game with 16x16 tiles. I wrote
it in pascal / 286 assembler for 320x200x8 bit and It ran like
the blazes on my pentium 200.
My point being, if you are running at a suitably low res, then
there must be some hell of a bottleneck in your code.
care to give us some snippets to look at?
----------
Disco Love For Everyone
the moment is for a top-down shoot ''em up (see rayden fighters,
raptor, etc) and the backgrounds in those games are mostly static. So I''ve sort of let this bias my answer.
I once coded a little dungeon game with 16x16 tiles. I wrote
it in pascal / 286 assembler for 320x200x8 bit and It ran like
the blazes on my pentium 200.
My point being, if you are running at a suitably low res, then
there must be some hell of a bottleneck in your code.
care to give us some snippets to look at?
----------
Disco Love For Everyone
----------"i think that all this talking and such is paining my head to astounding annoyance" - Erick"Quoting people in your tag is cool. Quoting yourself is even cooler" - SpazBoy_the_MiteyDisco Love For Everyone
Thankyou for all replies.
I''m running 640x480x16. I''d made a real misstake in the code. It''s running well now.
I''m running 640x480x16. I''d made a real misstake in the code. It''s running well now.
I agree with the pregeneration thing, but on a smaller scale. Instead of pregenerating screens, pregenerate strips of tiles. For example, if you''re moving right:
First off, make the whole initial screen in a buffer, but 1 or 2 tiles bigger in each dimension. Now when you go right, adjust the offset of where this buffer is blitted to the screen. Because the buffer is a tile width bigger than the screen, this will look okay, until you move over the tile (16 pixels). Then blit over your buffer, onto the buffer, but with an offset of 16 pixels to the left, then add in your strip in the space on the right.
To get animated pixels and overlap, add these in after individually. Only add in overlays where they''re important (over the characters/NPC''s).
Man, tile games are fun to make. Too bad today''s gamers don''t think they''re fun...
(with very few exceptions...)
First off, make the whole initial screen in a buffer, but 1 or 2 tiles bigger in each dimension. Now when you go right, adjust the offset of where this buffer is blitted to the screen. Because the buffer is a tile width bigger than the screen, this will look okay, until you move over the tile (16 pixels). Then blit over your buffer, onto the buffer, but with an offset of 16 pixels to the left, then add in your strip in the space on the right.
To get animated pixels and overlap, add these in after individually. Only add in overlays where they''re important (over the characters/NPC''s).
Man, tile games are fun to make. Too bad today''s gamers don''t think they''re fun...
(with very few exceptions...)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement