2D tiled game engine – use C # in XNA in XNA

I plan to build an advanced 2D Up-Down RPG.

It will be the C# of my existing 2D Flash RPG engine (Adobe Air) XNA version.

Well, in Flash Pro, I just use different MovieClips for different layers, but how can I implement it in C# using XNA?

I want to be able to use the output (map-data-file) in the Flash Map Editor I made.

The output file is as follows:


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


.....
.. .
.
.


.
.
.

Wait…

Where:

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

So I want to simply iterate through these rows, save them in an array and add the corresponding sprites to a specific layer, it may look like this:

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

How can I realize this? And, how can I manage the z-sort, so I want to be able to walk under the bridge, or drive through the tunnel.

(Like in this picture, there may be a ship driving on the bridge)

p>

Even some stairs enter the next stage (switch level)

Do you have any thoughts or even reflections on me?

thx all your answers!

Edit:

The layer hirachy shoult 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
SpriteBatch.Draw method has an overload that allows you to specify Layer

Specifically, the table There are two entries at the bottom of here

The layer is a floating point number between 0 and 1. You also need to specify SpriteSortMode in SpriteBatch.Begin(). Below is a chessboard I wrote An example of the game, this board game colors player tokens and moves the active player to the top of the stack, so that when multiple 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 can help.

I plan to build an advanced 2D Up-Down RPG.

It will be my existing 2D Flash RPG The C# XNA version of the engine (Adobe Air).

Well, in Flash Pro, I just use different MovieClips for different layers, but how can I implement it in C# using XNA ?

I want to be able to use the output (map-data-file) in the Flash Map Editor I made.

The output file is as follows:


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


.....
.. .
.
.


.
.
.

Wait…

Where:

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

So I want to simply iterate through these rows, save them in an array and add the corresponding sprites to a specific layer, it may look like this:

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

How can I realize this? And, how can I manage the z-sort, so I want to be able to walk under the bridge, or drive through the tunnel.

(Like in this picture, there may be a ship driving on the bridge)

p>

Even some stairs enter the next stage (switch level)

Do you have any thoughts or even reflections on me?

thx all your answers!

Edit:

The layer hirachy shoult 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

The SpriteBatch.Draw method has an overload that allows you to specify Layer

Specifically, there are two entries at the bottom of the table here

< p>The layer is a floating point number between 0 and 1. You also need to specify the SpriteSortMode in SpriteBatch.Begin(). Below is an example of a board game I wrote that colors player tokens And move the active player to the top of the stack so that when multiple players occupy the same square:

if (i == currentPlayer)
{
SpriteCol or = 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.

Leave a Comment

Your email address will not be published.