Jump to content
  • Advertisement
Sign in to follow this  
Roots

Your game: how many layers?

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

Out of curiousity, I wanted to ask how many layers (of tiles, objects, or whatever) you all use in your game, and what you use each layer for. We're still working out the details in how many layers my game will have (we may add some more), but for now this is a tentative list: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Tile Layers Map tiles are drawn in three different layers: * Lower Layer: usually used for tiles that represent the ground * Middle Layer: tiles used to put variation into lower layer tiles, and also used for map lighting. * Upper Layer: tiles for effects such as smoke which should always be drawn over the ground layers and ground objects. None of the three layers are required to be completely filled with valid tiles. It is perfectly valid, in fact, for a tile layer to contain no tiles at all (though such situations will likely be rare). Object Layers Map objects are also arranged into three layers * Ground Objects: used for objects that are affixed to the ground, and most of the sprites. * Middle Objects: special objects (like bridges) which may be walked under or above on by other objects/sprites. * Sky Objects: objects that are flying high in the sky and are unaffected by all three tile layers drawn below. Map Layer Drawing Order All tile and object layers are drawn in the same order every frame. The only oddity is that ground objects are drawn in two passes so that middle objects can be both walked under and above on. In which pass each ground object is drawn to is determined by its altitude. The drawing order is as follows: 1) Lower Tile Layer 2) Middle Tile Layer 3) Ground Object Layer (first pass) 4) Middle Object Layer 5) Ground Object Layer (second pass) 6) Upper Tile Layer 7) Sky Object Layer <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< So that's how we're currently doing things, and so far its working out well. There is some talk of a fourth tile layer so we can do things like have grass drawn over a sprite's feet, etc. What have the rest of you done in the past/current projects, and why? (Any comments on our layer method I posted above are welcome by the way.)

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I use 4 tile layers:

Ground - All base tiles are put here such as grass or sand.
Above Ground - Things such as flowers, trees, bushes and barrels go on this layer.
Wall - Walls go on this layer, such as the brick walls in a castle or the wood walls on a house.
Roof - The roofs for houses and such would go on this layer.

Including 2 additional layers, they are ordered as follows:

1. Ground
2. Above Ground
3. Items
4. Sprites
5. Wall
6. Roof

This allows for a nice level of detail on maps.

-VBStrider

Share this post


Link to post
Share on other sites
I am no longer working with my tile engine, but this is how I did it:

I didn't have a defined set of layers -- rather, my entire layer system was completely dynamic. I could put whatever the crap I wanted in any layer, have as many layers as I wanted, etc.

Each map had one layer by default. I called it the "Interactive" layer because it was where most of the action would happen, but it could have been used for anything.

All other layers added to the map were either "background" or "foreground" -- background meant they were rendered before the Interactive layer was; foreground meant they were rendered after the Interactive layer was.

So my rendering code rendered all the background layers, then the interactive layer, then all the foreground layers.

I did however make all layers besides the Interactive one be of one of the following two types:

Stationary: did not move when the map was scrolled
Parallax: this moved relative to the layer before or after it (whichever one was "closer" to the Interactive layer).

All layers also managed a list of game objects, and the objects moved relative to the position of the layer.

I never actually made a game with this, so I can't tell you how well it works for a large project.

Share this post


Link to post
Share on other sites
Quote:
Original post by Roots
Out of curiousity, I wanted to ask how many layers (of tiles, objects, or whatever) you all use in your game, and what you use each layer for. We're still working out the details in how many layers my game will have (we may add some more), but for now this is a tentative list:


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Tile Layers

Map tiles are drawn in three different layers:

* Lower Layer: usually used for tiles that represent the ground
* Middle Layer: tiles used to put variation into lower layer tiles, and also used for map lighting.
* Upper Layer: tiles for effects such as smoke which should always be drawn over the ground layers and ground objects.

None of the three layers are required to be completely filled with valid tiles. It is perfectly valid, in fact, for a tile layer to contain no tiles at all (though such situations will likely be rare).


Object Layers

Map objects are also arranged into three layers

* Ground Objects: used for objects that are affixed to the ground, and most of the sprites.
* Middle Objects: special objects (like bridges) which may be walked under or above on by other objects/sprites.
* Sky Objects: objects that are flying high in the sky and are unaffected by all three tile layers drawn below.


Map Layer Drawing Order

All tile and object layers are drawn in the same order every frame. The only oddity is that ground objects are drawn in two passes so that middle objects can be both walked under and above on. In which pass each ground object is drawn to is determined by its altitude. The drawing order is as follows:

1) Lower Tile Layer
2) Middle Tile Layer
3) Ground Object Layer (first pass)
4) Middle Object Layer
5) Ground Object Layer (second pass)
6) Upper Tile Layer
7) Sky Object Layer
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


So that's how we're currently doing things, and so far its working out well. There is some talk of a fourth tile layer so we can do things like have grass drawn over a sprite's feet, etc. What have the rest of you done in the past/current projects, and why?


(Any comments on our layer method I posted above are welcome by the way.)


I'm unsure as to why you chose to have the Upper tile layer.. from what I can see the functionality of this has already been given in the Sky object Layer.. if you need to have objects that are always drawn above every other tile and aren't tested for collision then the sky object layer should be fine..

Share this post


Link to post
Share on other sites
That's a good point. The upper tile layer is mostly for animated things that always appear over the ground objects, like smoke from a fire. The sky objects are things that are flying high in the sky, such as birds, clouds, or winged warriors. The sky objects are high enough that the upper tile layer doesn't effect them.


The upper tile layer is also used to make tiles that should always be drawn over the player that are solid, such as the top of walls (so the player can walk behind walls and other structures. Does that make more sense?

Share this post


Link to post
Share on other sites
Oook.. that makes sense..

So that means upper tile in the upper tile layer could always stay static relative to their position on the layer..

That way you can have all the dynamic entities as objects rather than tiles..

Good point..

Are your objects restricted in terms of size (uniform like the tiles are) or are their sizes variable?

Share this post


Link to post
Share on other sites
Objects can be any size, but are abstracted as being the size of x by y tiles. A normal sprite is the same as a 1x2 object, and no ground object can occupy the same tile. However, a sprite can be drawn "behind" another sprite if the top sprite is standing on the tile directly above the bottom sprite (if that makes sense).


[ ][ y][ ]
[ ][xy][ ]
[ ][x ][ ]


In the above, you see a sprite x and a sprite y, and the lower half of sprite y is drawn before the upper half of sprite x. Basically you are able to define any number of rows of the sprite that should be "not occupied" by any other object. So if I had a huge 4x6 tree and I want sprites to be able to walk behind the top 3 rows of it, that is easily done. [smile]


Sky objects are still kind of a grey area though, and I think I'm just going to let them each occupy however many tiles they want (so no collision detetcion), but the same draw methodology will apply so objects can be 'behind' other objects. Sky objects mostly exist for scripting purposes anyway.

Share this post


Link to post
Share on other sites
Layers in my engine? Lot of them actually [smile]

VISIBLE LAYERS :)
- background layer (for dirt)
- plant layer (for grass, flowers, small living stuff etc. blended with
previous layer)
- liquid layer (for water, lava etc, blended with previous two layers)
- shadow layer
- plant II layer for trees and larger living stuff
- object layer (buildings, rocks)
- living creatures layer
- elemental layera (snow, rain, fog)
- effect layer (for now only works with magic)

INVISIBLE LAYERS
- switch layer (has its own language similar to basic, if player step on xy then do some nice/nasty things)
- passability layer
- environment layers (temperature, humidity, life-force, magic energy)
these layers are engine which actually impacts on whole world,high temperatures burnes living matter, humidity make fog,raining or wind , life-force makes plants to grow or not, and magic layer for percent of succesfull magic attempts...

I think I wrote them all :) I'm not sure.


Share this post


Link to post
Share on other sites
Wow, why so many layers? I mean, did you just decide to put nearly everything in its own layer and not try to re-use layers for more than one purpose? Like for your "object layer (buildings, rocks)" and "living creatures layer", how do you order those in the drawing? What if you have a character that walks behind a building? If you always draw your object layer before your living layer, the character will always be drawn over the building. And if you reverse the situation, the opposite is true. How do you handle that, and why do you handle it that way?


Also, what data structures are these layers contained in? Ie, are they all arrays (which can have empty locations), or are they just a list of objects? I tried not to have too many tile layers (which are 2D arrays) because if there's a lot of empty tiles, that's wasted memory and I want my game to not require a large memory footprint (but I still want the maps to be drawn fast).


One more thing [smile]. Couldn't you combine your "invisibile" layers easily? For example, technically my maps has an invisible layer of tile properties (but I don't call it a layer like you do). The properties layer is basically just a bit mask for things like passability, treasure, and three types of events: arrival, departure, and confirm. (An arrival event occurs when the player steps on the tile, etc.). The events are actually contained in a list and when I detect an event occurs, I go to that list and look up the event that corresponds to that tile and then process it if it should be processed.

Share this post


Link to post
Share on other sites
Quote:
Original post by Roots
Objects can be any size, but are abstracted as being the size of x by y tiles. A normal sprite is the same as a 1x2 object, and no ground object can occupy the same tile. However, a sprite can be drawn "behind" another sprite if the top sprite is standing on the tile directly above the bottom sprite (if that makes sense).


[ ][ y][ ]
[ ][xy][ ]
[ ][x ][ ]


In the above, you see a sprite x and a sprite y, and the lower half of sprite y is drawn before the upper half of sprite x. Basically you are able to define any number of rows of the sprite that should be "not occupied" by any other object. So if I had a huge 4x6 tree and I want sprites to be able to walk behind the top 3 rows of it, that is easily done. [smile]


Sky objects are still kind of a grey area though, and I think I'm just going to let them each occupy however many tiles they want (so no collision detetcion), but the same draw methodology will apply so objects can be 'behind' other objects. Sky objects mostly exist for scripting purposes anyway.


Wow I like your design methodology.. You don't mind if I borrow some of your design concepts for my own tile-based engine?

I'm not building a top-down RPG as such, more of a side-scrolling stealth actioner but the use of tiles and layers still makes good sense from an implementational perspective..

I just thought I'd ask to be on the safe side (since stealing ideas is not something I make a habit of.. but in this case the quality of the concept leads me to believe I could make an acception.. provided i'm allowed to of course..)

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!