Jump to content
  • Advertisement
Sign in to follow this  
drarem

2D tile engine help

This topic is 5477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok I decided to post the question here as I need ideas on how to structure my 2D tile engine.. I want to display a background, a tile layer, a sprite layer, then finally an overhead layer. Coding the engine as such is not what i would want for the user: DrawBackground(); DrawTileLayer(); DrawSprites(); DrawRoof(); Flip(); I would rather do this: Update(); //may just have a background and sprite layer for //simple games Flip(); Do I need to do dirty rectangles, if so where and how? From experience, using arrays to store the tilemaps seems the way to go, however it seems if I only display the onscreen tiles it would run faster - is that possible and how? And why does GDI seemed to have slowed down since I was forced to install the .NET framework?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by drarem
Do I need to do dirty rectangles, if so where and how?

For best performance, yes. You wil have to use dirty rectangles in that case. I'd suggest getting the basic sub-functionality you described working first, though.

Quote:

From experience, using arrays to store the tilemaps seems the way to go, however it seems if I only display the onscreen tiles it would run faster - is that possible and how?

Yes, it will run much faster.
Let's say your tiles are 16x16 and your window size is 800x600, this will result in 50x38 visible tiles.

If your scroll offset (I assume tile-wise scrolling - smooth scrolling isn't that hard to do once you've got this working) is as map position (mapX,mapY), you can use this loop to render only visible portions of your map (assuming C++/C# here):

// something like that would draw only the visible portion of the map
int screenPosY = 0;
for (int y = mapY; y < mapY + TilesPerCol; ++y) {
// reset horizontal screen position
int screenPosX = 0;
for (int x = mapX; x < mapX + TilesPerRow; ++x) {
DrawTile (tileLayer[y][x], screenPosX, screenPosY);
if (HaveSpritesAt(x, y)) {
for (int i = 0; i < NumberOfSpritesAt(x,y); ++i) {
DrawSprite(GetSpriteAt(x, y, i), screenPosX, screenPosY);
}
}
DrawTile (roofLayer[y][x], screenPosX, screenPosY);
screenPosX += TileSizeX;
}
screenPosY += TileSizeY;
}


Quote:

And why does GDI seemed to have slowed down since I was forced to install the .NET framework?

Which programming environment do you use? .NET (WinForms etc. together with managed C++, C# or VB.NET), plain C++ with native Win32 API or MFC?
It seems strange because AFAIK GDI+ only affects .NET applications...

Share this post


Link to post
Share on other sites

if (HaveSpritesAt(x, y)) {
for (int i = 0; i < NumberOfSpritesAt(x,y); ++i) {
DrawSprite(GetSpriteAt(x, y, i), screenPosX, screenPosY);
}
}


Ahhh... I see.. and if the tiles are 16x16 and the sprite moves 1 pixel at a time, how would I interpolate that as to which tile it belongs? The perspective? What if the sprite was in the middle of tile 3 and 4, or should I draw 9 tiles at a time instead and then draw sprites within the boundary?

Does that make sense?

And I'm using the normal GDI/bitblt, on my P4 3.0Ghz it still kinda tears when the bitmap is moving fast across the screen (increments of 4 or more).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Maby you can find somthing that can help at this site:
http://2dnow.zenzer.net/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!