Tile-based 2D game engine - layer management in XNA with C #

I am going to create an advanced 2D-Up-Down RPG.

This will be the C # + XNA version of my existing 2D Flash RPG Engine (Adobe Air).

Well, in Flash Pro, I just used different clicks for different layers, but how could I understand that in C # using XNA?

I want to be able to use the output (data card file) from the flash card editor I created.

The output file is as follows:

<layer1> 0.0.0.AAAABBAA0.0.0 0.0.0.AAAABBBAA0.0 0.0.AAABBBBBBA0.0 0.AAAABBBBBBAA0 0.AAAABBBBBBAA0 0.AAAAABBBBB:BA0 0.0.AAAABBBBAAA0 0.0.AAAAABBAAA0.0 0.0.0.AAAABBAA0.0.0 <layer2> . . . . . . . . . . <layer3> . . . 

and so on...

Where:

 0 = Blank; A = Gras; B = Water; 

so I just want to skip these lines, save the arrays and add the corresponding sprites to a specific layer, perhaps like this:

 Layers[2].Add( tile, x, y ); 

How can I understand that? as well as how I can manage z-sorting because I want me to be able to walk under bridges or drive through tunnels.

(as in this image, there may be a ship leading to the bridge)

enter image description here

or even some stairs to go to the next stage (switch layer)

Do you guys have an idea or even a review for me?

Thanks for all your answers!

EDIT:

hirachy shoult layer looks like this:

 map{ Layer[0] { // "bg" xyArray{ .... } } Layer[1] { // "static" - bottom part / stairs of the bridge xyArray{ .... } } Layer[2] { // "items" xyArray{ .... } } Layer[3] { // "player" xyArray{ .... } } Layer[4] { // "static2" - top part of bridge xyArray{ .... } } } // if the player is ON a tile that hat a Stair funktion, the "player" layer will be // moved on top of the "static2" layer, so 'Layer[3].Z = 4;' and 'Layer[4].Z = 3;' // like i showed in the Switch funktion up there 
+4
source share
1 answer

The SpriteBatch.Draw method has overloads that let you specify a Layer

In particular, the bottom two entries in the table here

A layer is a float between 0 and 1. You also need to specify SpriteSortMode in SpriteBatch.Begin() . The following is an example from a board game that I wrote that shades a playerโ€™s tokens and moves the active player to the very front of the stack when several players occupy the same square:

 if (i == currentPlayer) { SpriteColor = Color.White; spriteDepth = 0f; // Front } else { SpriteColor = Color.Gray; spriteDepth = 0.1f; // Back } spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); spriteBatch.Draw(players[i].Sprite, SquareCentre, null, SpriteColor, 0f, SpriteCentre,0.5f, SpriteEffects.None, spriteDepth); spriteBatch.End(); 

Hope this helps.

+1
source

All Articles