[英]Superposition problem with 2D Sprites (XNA)
这可能是一个noob问题,但在这里......
我将Visual Studio与XNA Framework(3.1)结合使用,并且只打算为我的游戏绘制2D精灵,这是主类中的Draw方法:
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
background.Draw(this.spriteBatch);
player1.Draw(this.spriteBatch);
player2.Draw(this.spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
问题在于玩家2与玩家1重叠(因为他是在之后被吸引),我希望从玩家的位置(在位置上)将两个玩家中最低的一个(模拟深度)绘制。
提前致谢! (对不起,我是法国人...)
SpriteBatch.Draw方法有一个重载,它提供了一个“ layerDepth”参数(从0表示前面,到1表示后面)。 您可以设置单个精灵的layerDepth,并在SpriteBatch.Begin方法中使用spriteSortMode.BackToFront。
好的,感谢史蒂夫,我做到了。 我刚刚将我的玩家SpriteBatch.Draw方法更改为SpriteBatch.Draw(X,X,(...),layerDepth),并使用layerDepth更新了玩家的Y位置。 不得不使用spriteSortMode.FrontToBack:因为原点在左上角,一切都被颠倒了。 谢谢!
史蒂夫的答案可能是最简单的,但有时立即绘图是有利的。 另一种方法是根据Y轴对列表中的玩家和对象进行排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.