Jump to content
  • Advertisement
Sign in to follow this  
MarioGarc

Creating a Tile Engine: Design Questions

This topic is 2782 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

Hi there, guys.

I've been working a little on my own, creating a tiled map and a camera system to scroll around it. I got it to work but, since I was just programming (XNA 4, though that doesn't matter right now) it on the fly to see if I could do it, the code is pretty messed up.

Now I'm trying to code it properly, so before I start I've been thinking about the best.way to do it. Here are some questions I have. I hope you can give me some hints to answer them:

1 - I was thinking of having a TileMap and a Tile class. The TileMap would have an array of integers property, representing the different kind of tiles available. Then, since I would just have to draw the tiles being inside the camera view, should I create the Tile objects needed on every Update call?

2 - Is there any recomended design pattern for games, or tiled games? I have worked with the Model-View-Controller pattern before, but it doesn't exactly fit what I want right now, any suggestions?



PS: I hope my English is good enough for you to understand me, but I'm aware the text will probably contain many mistakes. Thanks for your help :)

Share this post


Link to post
Share on other sites
Advertisement
1: That sounds fair. How about searching the forums for QuadTree,
which is both a popular and efficient way to manage a tile-based map.

2: There are many! :D you mention the mvc pattern, which actually fits well if you just seperate the domain ideas a bit. You need a map to display, and another to physically represent the tile, then you could fit a control part onto that and complete the pattern while making the bits of your project internally independent. But the best design is the one that suits your exact scenario best. Best practice with a twist of tailor-made.

Share this post


Link to post
Share on other sites


1 - I was thinking of having a TileMap and a Tile class. The TileMap would have an array of integers property, representing the different kind of tiles available. Then, since I would just have to draw the tiles being inside the camera view, should I create the Tile objects needed on every Update call?

Create tile objects? There should be pointers from tile map cells to a few immutable Tile objects (one per "kind"); information that can be different for each tile of the same kind (e.g. what stuff is on that tile, or transient modifications like having fog of war or not) should be stored in other fields of the main tilemap entry or even in separate data structures (e.g. a map indexed by map location for particularly sparse data).

No objects should be normally created or destroyed in tilemap updates; even changing tile types is only a pointer swap. You can also avoid most memory allocations by recycling old object instances through an object pool.

Share this post


Link to post
Share on other sites

2 - Is there any recomended design pattern for games, or tiled games? I have worked with the Model-View-Controller pattern before, but it doesn't exactly fit what I want right now, any suggestions?

There are many popular design patterns, and they mostly conflict with each other: you should ask for advice when you already have a problem, or the advice will be wrong.
For example, you think a MVC design is a bad fit for your game: if you explain what you don't like, I'm sure someone will suggest something more suitable.

Share this post


Link to post
Share on other sites

1: That sounds fair. How about searching the forums for QuadTree,
which is both a popular and efficient way to manage a tile-based map.

2: There are many! :D you mention the mvc pattern, which actually fits well if you just seperate the domain ideas a bit. You need a map to display, and another to physically represent the tile, then you could fit a control part onto that and complete the pattern while making the bits of your project internally independent. But the best design is the one that suits your exact scenario best. Best practice with a twist of tailor-made.


Thank you very much!!

I have been reading about the QuadTree structure you just mentioned. I had never heard of it, and it seems really interesting.



[quote name='Attan' timestamp='1303915397' post='4803557']
1 - I was thinking of having a TileMap and a Tile class. The TileMap would have an array of integers property, representing the different kind of tiles available. Then, since I would just have to draw the tiles being inside the camera view, should I create the Tile objects needed on every Update call?

Create tile objects? There should be pointers from tile map cells to a few immutable Tile objects (one per "kind"); information that can be different for each tile of the same kind (e.g. what stuff is on that tile, or transient modifications like having fog of war or not) should be stored in other fields of the main tilemap entry or even in separate data structures (e.g. a map indexed by map location for particularly sparse data).

No objects should be normally created or destroyed in tilemap updates; even changing tile types is only a pointer swap. You can also avoid most memory allocations by recycling old object instances through an object pool.
[/quote]

Damn, spent too much time programming in Java and forgot about pointers :unsure: So I guess I should just create a parent Tile class and one static subclass for each possible tile in the game, am I right?

Thank you very much too, these comments will be really helpful for me.

Share this post


Link to post
Share on other sites

Damn, spent too much time programming in Java and forgot about pointers :unsure: So I guess I should just create a parent Tile class and one static subclass for each possible tile in the game, am I right?

No, I mean one Tile class with a few instances, one per tile kind, containing the different graphics and all flags and properties that describe tile behaviour (e.g. lava hurts? damagePerSecond=3; walls are solid? passable=false). Such objects are going to be read-only because they are shared by many map cells.

Note that it would be exactly the same in Java and in C++, and that a tile kind "pointer" can be an array index or a name.

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!