<bdo id='camSY'></bdo><ul id='camSY'></ul>
<tfoot id='camSY'></tfoot>

    1. <small id='camSY'></small><noframes id='camSY'>

      <legend id='camSY'><style id='camSY'><dir id='camSY'><q id='camSY'></q></dir></style></legend>
        <i id='camSY'><tr id='camSY'><dt id='camSY'><q id='camSY'><span id='camSY'><b id='camSY'><form id='camSY'><ins id='camSY'></ins><ul id='camSY'></ul><sub id='camSY'></sub></form><legend id='camSY'></legend><bdo id='camSY'><pre id='camSY'><center id='camSY'></center></pre></bdo></b><th id='camSY'></th></span></q></dt></tr></i><div id='camSY'><tfoot id='camSY'></tfoot><dl id='camSY'><fieldset id='camSY'></fieldset></dl></div>

        如何在 libgdx Stage 中对 Actor 进行排序?

        时间:2023-05-20
      1. <small id='76DKc'></small><noframes id='76DKc'>

          <bdo id='76DKc'></bdo><ul id='76DKc'></ul>
              <tfoot id='76DKc'></tfoot>
                <tbody id='76DKc'></tbody>

            • <i id='76DKc'><tr id='76DKc'><dt id='76DKc'><q id='76DKc'><span id='76DKc'><b id='76DKc'><form id='76DKc'><ins id='76DKc'></ins><ul id='76DKc'></ul><sub id='76DKc'></sub></form><legend id='76DKc'></legend><bdo id='76DKc'><pre id='76DKc'><center id='76DKc'></center></pre></bdo></b><th id='76DKc'></th></span></q></dt></tr></i><div id='76DKc'><tfoot id='76DKc'></tfoot><dl id='76DKc'><fieldset id='76DKc'></fieldset></dl></div>
              <legend id='76DKc'><style id='76DKc'><dir id='76DKc'><q id='76DKc'></q></dir></style></legend>

                  本文介绍了如何在 libgdx Stage 中对 Actor 进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在对 LibGdx Stage 对象中的 Actor 进行排序时遇到问题.当舞台被渲染时,图像会按照它们添加的顺序被渲染.Stage 使用一个数组来保存 Actor.我已经尝试设置每个 Actor 的 ZIndex,但它仍然没有排序.然后我尝试像这样创建一个比较器对象:

                  I'm having trouble sorting Actors in a LibGdx Stage object. When the Stage gets rendered the images are rendered in the order they are added. Stage uses an Array to hold the Actors. I've tried setting the ZIndex of each Actor, but it still didn't sort. Then I tried creating a comparator object like this:

                  public class ActorComparator implements Comparator < Actor > {
                      @Override
                      public int compare(Actor arg0, Actor arg1) {
                          if (arg0.getZIndex() < arg1.getZIndex()) {
                              return -1;
                          } else if (arg0.getZIndex() == arg1.getZIndex()) {
                              return 0;
                          } else {
                              return 1;
                          }
                      }
                  }
                  

                  然后当我想进行实际比较时:

                  and then when I want to do the actual comparison I did:

                  Collections.sort(Stage.getActors(), new ActorComparator());
                  

                  它给了我以下错误并且不会编译:

                  It gives me the following error and won't compile:

                  The method sort(List<T>, Comparator<? super T>) in the type Collections 
                  is not applicable for the arguments (Array<Actor>, ActorComparator)
                  

                  我不知道我做错了什么.谁能给我解释一下?

                  I have no clue what I'm doing wrong. Can someone explain this to me?

                  推荐答案

                  看起来你的代码 Stage.getActors() 返回一个 Array of Actors 而不是 List.Collections.sort() 方法只接受列表.试试:

                  Looks like your code Stage.getActors() returns an Array of Actors instead of a List. Collections.sort() method accepts only Lists. Try:

                  Collections.sort(Arrays.asList(Stage.getActors().toArray()), new ActorComparator());
                  

                  @James Holloway 的排序更新(按问题中的 z-index):z-index 被阶段覆盖为数组的内部顺序.因此,设置 Z-Index 没有任何效果,除非您将其设置为高于列表的长度,然后它只是将图像放在列表的顶部(内部 Stage 会这样做).这可以通过按名称或 ID 排序来解决.

                  Update on sorting (by z-index in the question) from @James Holloway: z-index is overridden by the stage to be whatever the internal order of the Array is. So setting the Z-Index has no effect, except in the case that you set it as higher than the length of the list and then it just puts the image on top of the list (internal Stage does this). This is solved by sorting by name or ID.

                  这篇关于如何在 libgdx Stage 中对 Actor 进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Android 上使用来自 libGDX 的 SQLite 下一篇:“AL lib:alc_cleanup:1 个设备未关闭"是什么意思

                  相关文章

                  最新文章

                1. <tfoot id='wTF6z'></tfoot>
                  <legend id='wTF6z'><style id='wTF6z'><dir id='wTF6z'><q id='wTF6z'></q></dir></style></legend>
                2. <i id='wTF6z'><tr id='wTF6z'><dt id='wTF6z'><q id='wTF6z'><span id='wTF6z'><b id='wTF6z'><form id='wTF6z'><ins id='wTF6z'></ins><ul id='wTF6z'></ul><sub id='wTF6z'></sub></form><legend id='wTF6z'></legend><bdo id='wTF6z'><pre id='wTF6z'><center id='wTF6z'></center></pre></bdo></b><th id='wTF6z'></th></span></q></dt></tr></i><div id='wTF6z'><tfoot id='wTF6z'></tfoot><dl id='wTF6z'><fieldset id='wTF6z'></fieldset></dl></div>
                3. <small id='wTF6z'></small><noframes id='wTF6z'>

                        <bdo id='wTF6z'></bdo><ul id='wTF6z'></ul>