Tile Engine question
Moderator: Coders of Rage
-
- Chaos Rift Junior
- Posts: 200
- Joined: Mon Feb 22, 2010 12:32 am
- Current Project: Breakout clone, Unnamed 2D RPG
- Favorite Gaming Platforms: PC, XBOX360
- Programming Language of Choice: C#
- Location: San Antonio,Texas
- Contact:
Tile Engine question
I'm building a tile Engine for a game I'm working on and had a question.
I'm looking at having a Tile class and a map class.
The map class would be a 2D array of Tiles and the tile class would have information about a "Tile" including an array that would hold the information for each layer for that tile.
In a game I would have an array of "map"s to build a level.
Currently, I'm looking for feedback on this design. What do you guys think?
I'm looking at having a Tile class and a map class.
The map class would be a 2D array of Tiles and the tile class would have information about a "Tile" including an array that would hold the information for each layer for that tile.
In a game I would have an array of "map"s to build a level.
Currently, I'm looking for feedback on this design. What do you guys think?
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Tile Engine question
Great design imo, I have used the exact same thing for 2 of my first games
Re: Tile Engine question
so like:
?
If that's along the lines of what you were thinking, I think that's a tad bit flawed.
Typically when you have different layers, you'll probably have like a ground layer, a couple object layers, maybe an item layer, etc.
So if any of these share the same (x, y) position, yet different layers, they will probably all need to hold different information to define itself.
So if a tile has an array that defines all the spaces in that (x, y) space through a number of layers, things will become a bit more complicated when two of those spaces in the layer aren't the same (and if they are the same, layers become useless...).
In my level editor / tile engine. I have maps defined as a dynamically allocated 3D array. So, I have width, height, and layers, and each one is a different tile. This way I can store information about each individual piece.
Sorry if my post seems a little confusing, but I hope it helps.
EDIT: After thinking about what I posted, perhaps I interpreted what you said a little wrong, did you perhaps mean something more like this:
? Because that seems like a great way to do it =D
Code: Select all
class Map
{
Tile** tiles;
};
class Tile
{
//Other tile stuff...
Layer* layer
};
If that's along the lines of what you were thinking, I think that's a tad bit flawed.
Typically when you have different layers, you'll probably have like a ground layer, a couple object layers, maybe an item layer, etc.
So if any of these share the same (x, y) position, yet different layers, they will probably all need to hold different information to define itself.
So if a tile has an array that defines all the spaces in that (x, y) space through a number of layers, things will become a bit more complicated when two of those spaces in the layer aren't the same (and if they are the same, layers become useless...).
In my level editor / tile engine. I have maps defined as a dynamically allocated 3D array. So, I have width, height, and layers, and each one is a different tile. This way I can store information about each individual piece.
Sorry if my post seems a little confusing, but I hope it helps.
EDIT: After thinking about what I posted, perhaps I interpreted what you said a little wrong, did you perhaps mean something more like this:
Code: Select all
class Map
{
Tile** tiles;
Tile* tileLayers;
};
class Tile
{
//Tile info
};
-
- Chaos Rift Junior
- Posts: 200
- Joined: Mon Feb 22, 2010 12:32 am
- Current Project: Breakout clone, Unnamed 2D RPG
- Favorite Gaming Platforms: PC, XBOX360
- Programming Language of Choice: C#
- Location: San Antonio,Texas
- Contact:
Re: Tile Engine question
I see what you are saying. I started with the 3D array concept but didn't want to get things too complex. =)
The gist would be to use a Tile to have a ground layer(grass, road, caves, etc) then have a layer for objects(treasure chests, etc)
I would have say an overworld "level" that would be similar to a "screen" in a game like zelda this would be a 2D array.
then the coordinate x,y in that array would be a "map" which in and of itself would be a 2D array of TIles.
That was the initial thought; however, I think once difference would be that in this design you would almost have to do it like The Legend of Zelda in order to only have one "Map" on the screen at once. If you used a 3D array you would be able to do more of a smooth scrolling around the world.
My inital problem was trying to think of a way to work on a "level" that goes beyond the bounds of a screen in a level editor.
Then again I really haven't put TOO much tought into this. =)
The gist would be to use a Tile to have a ground layer(grass, road, caves, etc) then have a layer for objects(treasure chests, etc)
I would have say an overworld "level" that would be similar to a "screen" in a game like zelda this would be a 2D array.
then the coordinate x,y in that array would be a "map" which in and of itself would be a 2D array of TIles.
That was the initial thought; however, I think once difference would be that in this design you would almost have to do it like The Legend of Zelda in order to only have one "Map" on the screen at once. If you used a 3D array you would be able to do more of a smooth scrolling around the world.
My inital problem was trying to think of a way to work on a "level" that goes beyond the bounds of a screen in a level editor.
Then again I really haven't put TOO much tought into this. =)
Re: Tile Engine question
Well if you still haven't found a solution to this, here's my two cents:mattheweston wrote: My inital problem was trying to think of a way to work on a "level" that goes beyond the bounds of a screen in a level editor.
Create a camera class, and only load the tiles that would be on screen. So with a few calculations, you can find where the top left corner of the game window should be, and from there, it's easy to find the rest of the rectangle. So you'd start with the tiles that would be at that (x, y) coordinate in the map, and tile until you reach the screen width and height.
-
- Chaos Rift Junior
- Posts: 200
- Joined: Mon Feb 22, 2010 12:32 am
- Current Project: Breakout clone, Unnamed 2D RPG
- Favorite Gaming Platforms: PC, XBOX360
- Programming Language of Choice: C#
- Location: San Antonio,Texas
- Contact:
Re: Tile Engine question
yeah I was going to have a variable for storing the top left corner of the tiles on screen. This is probably really easy stuff. I just have to think it through and not make it out to be harder than it is. =)
Re: Tile Engine question
Well, I'd say you should at least have a rectangle to hold the top left corner, width, and height, instead of only the top left cornermattheweston wrote:yeah I was going to have a variable for storing the top left corner of the tiles on screen. This is probably really easy stuff. I just have to think it through and not make it out to be harder than it is. =)
-
- Chaos Rift Junior
- Posts: 200
- Joined: Mon Feb 22, 2010 12:32 am
- Current Project: Breakout clone, Unnamed 2D RPG
- Favorite Gaming Platforms: PC, XBOX360
- Programming Language of Choice: C#
- Location: San Antonio,Texas
- Contact:
Re: Tile Engine question
Yes, I'll have a height and width as well. Not sure if I'll have two vector2D vars or one Rectangle yet.
Rectangle would make more sense.
Rectangle would make more sense.
- RyanPridgeon
- Chaos Rift Maniac
- Posts: 447
- Joined: Sun Sep 21, 2008 1:34 pm
- Current Project: "Triangle"
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/C++
- Location: UK
- Contact:
Re: Tile Engine question
This looks absolutely fine.XianForce wrote:so like:
Code: Select all
class Map { Tile** tiles; }; class Tile { //Other tile stuff... Layer* layer };
This is the way I would do it, although maybe not have a seperate Layer object for every layer, as some layers (like collision) might only need something as simple as a char value, and others might need much more complex information. Unless Layer is an abstract base type which would work fine, as long as you're not going too overboard on OOP.
This makes little sense.XianForce wrote:? Because that seems like a great way to do it =DCode: Select all
class Map { Tile** tiles; Tile* tileLayers; }; class Tile { //Tile info };
Last edited by RyanPridgeon on Tue Mar 23, 2010 11:26 am, edited 1 time in total.
Re: Tile Engine question
Yeah I realized I effed that up haha...RyanPridgeon wrote:This looks absolutely fine.XianForce wrote:so like:
Code: Select all
class Map { Tile** tiles; }; class Tile { //Other tile stuff... Layer* layer };
This is the way I would do it, although maybe not have a seperate Layer object for every layer, as some layers (like collision) might only need something as simple as a char value, and others might need much more complex information. Unless Layer is an abstract base type which would work fine, as long as you're not going too overboard on OOP.
This makes little sense.XianForce wrote:? Because that seems like a great way to do it =DCode: Select all
class Map { Tile** tiles; Tile* tileLayers; }; class Tile { //Tile info };
The second thing I posted is most definitely NOT the way to do it. I had a little brain malfunction there haha.
But the first way... What happens when you need information for a specific tile? If you have a 2D array of tiles, that accounts for the (x, y), but if the tiles hold something to represent each tile in that layer, that becomes a problem because they likely need to have different properties, and have all the properties any tile would. So the only way I could think that it would have the same properties, is if you made it another array of tiles within the tile class... which wouldn't really work, as it would be unending, right?
And just to fix the second one, what I probably meant to put was something like:
Code: Select all
class Map
{
Tile** tiles1;
Tile** tiles2;
//continue for amount of layers
};
But here's another suggestion:
Code: Select all
class Layer
{
Tile** tiles
};
class Map
{
std::vector<Layer> layers;
};
But then again, what do I know? I'm a nub
Re: Tile Engine question
since you are so pointer happy,
why not just go, Tile ***tiles; ?
why not just go, Tile ***tiles; ?
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
-
- Chaos Rift Junior
- Posts: 200
- Joined: Mon Feb 22, 2010 12:32 am
- Current Project: Breakout clone, Unnamed 2D RPG
- Favorite Gaming Platforms: PC, XBOX360
- Programming Language of Choice: C#
- Location: San Antonio,Texas
- Contact:
Re: Tile Engine question
All the C++ examples are great but, pointers won't be a problem as I'll be using C# and XNA. =)
Re: Tile Engine question
Oh, oops >.>mattheweston wrote:All the C++ examples are great but, pointers won't be a problem as I'll be using C# and XNA. =)
-
- Chaos Rift Junior
- Posts: 200
- Joined: Mon Feb 22, 2010 12:32 am
- Current Project: Breakout clone, Unnamed 2D RPG
- Favorite Gaming Platforms: PC, XBOX360
- Programming Language of Choice: C#
- Location: San Antonio,Texas
- Contact:
- LeonBlade
- Chaos Rift Demigod
- Posts: 1314
- Joined: Thu Jan 22, 2009 12:22 am
- Current Project: Trying to make my first engine in C++ using OGL
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: Blossvale, NY
Re: Tile Engine question
Better yet...avansc wrote:since you are so pointer happy,
why not just go, Tile ***tiles; ?
Code: Select all
Tile *******tiles;
There's no place like ~/