简体   繁体   English

LibGdx-如何为精灵设置图层

[英]LibGdx - How to set layers for the Sprites

Just for the start I'm new to the Java programming and especially to the LibGdx and I would like to ask community, because I have found some problem with Sprites, that I couldn't dealt with. 刚开始时,我是Java编程(特别是LibGdx)的新手,我想问一下社区,因为我发现了Sprites的一些我无法处理的问题。

I create a several Sprites with Textures and I've managed to create a small function game, but when it comes to slide over an Sprite, it moves across him correctly, but not the way I want it to happend. 我用纹理创建了几个Sprites,并且设法创建了一个小型函数游戏,但是当要在Sprite上滑动时,它可以正确地在他身上移动,但不是我希望它发生的方式。

For example there are Sprites A and B. B is static on the render screen and the A is moving towards him. 例如,有精灵A和B。B在渲染屏幕上是静态的,而A正在向他移动。 when the A is touching B and moving across B, I would like to be it, that A is at the top and the B is under the A, so it looks like the A is over the B. But in my case when this happens, the B is on top of A. So I'm asking if there is anyway how to set some privileg to be drawn at the top of other Sprite or, is there a better way to acomplish it. 当A触摸B并在B上移动时,我想成为的是A在顶部,而B在A之下,所以看起来A在B之上。但是在我的情况下,B位于A的顶部。所以我想问是否有办法设置在其他Sprite顶部绘制的privileg,还是有一种更好的方法来完成它。

Thanks for the support and help. 感谢您的支持和帮助。

It all depends on the order you write you code. 这完全取决于您编写代码的顺序。 In your renderer you should have something like : 在渲染器中,您应具有以下内容:

    spriteBatch.begin();
    spriteB.draw(spriteBatch);
    spriteA.draw(spriteBatch);
    spriteBatch.end();

In this case, you draw spriteB first, and then you draw spriteA. 在这种情况下,首先绘制spriteB,然后绘制spriteA。 That will make appear sprite A on top of spriteB. 这将使精灵A出现在spriteB的顶部。

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

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