简体   繁体   English

二维深度系统方法 XNA C#

[英]2D Depth System Method XNA C#

I am creating a 2D Top-Down RPG game like the Legend of Zelda: A link to the past.我正在创建一个 2D 自上而下的 RPG 游戏,比如塞尔达传说:过去的链接。

when the player is drawn i want to update the tree depth so that it is over and under the player when the player Y position is higher or lower than the trees Y position, i think whether the tree is on top or not should be decided by the players Y position, being lower or higher.当玩家被绘制时,我想更新树的深度,以便当玩家 Y 位置高于或低于树 Y 位置时它在玩家上方和下方,我认为树是否在顶部应该由玩家 Y 位置,较低或较高。 is it possible to do this in this way?有没有可能以这种方式做到这一点? can i change the layer depth in the update method?我可以在更新方法中更改图层深度吗?

I'm not sure you can.我不确定你能不能。 i'm not very experienced when coding.我在编码时不是很有经验。 If there's a right way of doing this even without useing the spriteBatch layer depth i would appreciate any help.如果即使不使用 spriteBatch 层深度也有正确的方法,我将不胜感激。

I have discovered how to use the layer depth in the我发现了如何使用图层深度

spriteBatch.Draw();

Method.方法。

What i am attempting to do is shown in the images below我正在尝试做的如下图所示

树前的女人

树后的女人

The code i am using to separate trees from grass tiles uses layer depth like below:我用来将树木与草图块分开的代码使用如下图层深度:

spriteBatch.Begin(SpriteSortMode.FrontToBack, blendState = null, samplerState = null, DepthStencilState.DepthRead);

spriteBatch.Draw(tree, treePos, null, null, Vector2.Zero, 0, null, Color.White, SpriteEffects.None, 0.6f);

spriteBatch.End();

Tile draw method for the平铺绘制方法

tile

has the float value set设置了浮点值

0.5f

绘制带有值和意义的图像线

Here's a way to do it:这是一种方法:

Slice your sprites and do tile-based rendering, starting from the ground up to the sky.切片您的精灵并进行基于图块的渲染,从地面开始到天空。

Say you have a tile grid whose each is 32*32 pixels, if you have a tree that is 32*96 pixels, then when sliced it will be like:假设你有一个 32*32 像素的平铺网格,如果你有一棵 32*96 像素的树,那么当它被切片时,它会是这样的:

A // layer 2
A // layer 1
A // layer 0 (floor)

Logic:逻辑:

  • draw all tiles on floor 0绘制第 0 层的所有瓷砖
  • draw all tiles on floor 1绘制第 1 层的所有瓷砖
  • etc ...等等 ...

Then obviously the part that should hide your player will be drawn correctly (before, if player is behind).那么显然应该隐藏玩家的部分将被正确绘制(之前,如果玩家落后)。

(note that the lowest tile of the tree should not be walk-able) (请注意,树的最低瓷砖不应该是可行走的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM