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

    <small id='hPwmC'></small><noframes id='hPwmC'>

        <bdo id='hPwmC'></bdo><ul id='hPwmC'></ul>
    1. <tfoot id='hPwmC'></tfoot>

        LibGDX - 正确使用多边形类

        时间:2023-05-19

          <small id='o1FjY'></small><noframes id='o1FjY'>

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

              • <bdo id='o1FjY'></bdo><ul id='o1FjY'></ul>
                <legend id='o1FjY'><style id='o1FjY'><dir id='o1FjY'><q id='o1FjY'></q></dir></style></legend>
                    <tbody id='o1FjY'></tbody>
                • 本文介绍了LibGDX - 正确使用多边形类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我创建了 Polygon 对象来包裹我的飞机(飞机的 TextureRegion 大小是 256x74,但游戏中这个大小是 70x20).所以:

                  I have created Polygon object to wrap my airplane (size of airplane's TextureRegion is 256x74, but size of this one in a game is 70x20). So:

                  TextureRegion[] texRegsAirplane = TextureRegion.split(textureAirplane, 256, 74);
                  Rectangle bounds = new Rectangle(0, 0, 70, 20);
                  Polygon polygon = new Polygon(new float[]{0,0,bounds.width,0,bounds.width,bounds.height,0,bounds.height,0,0});
                  

                  之后在我的 update 函数中更新它的位置:

                  After that in my update function I update position of it:

                  public void update(float delta){
                      Vector2 v = getPosition();      
                      v.add(velocity);
                      polygon.setPosition(v.x, v.y);
                  }
                  

                  然后我渲染多边形以知道它在哪里:

                  Then I render polygon to know where it is:

                  public void render(SpriteBatch spriteBatch, float pixelPerUnitX, float pixelPerUnitY){
                  spriteBatch.draw(testTexture,polygon.getX()*pixelPerUnitX, polygon.getY()*pixelPerUnitY, 
                              polygon.getBoundingRectangle().width*pixelPerUnitX,polygon.getBoundingRectangle().height*pixelPerUnitY);
                  }
                  

                  最后,我创建了 2 架飞机并让它们相互飞行,每次迭代我都尝试检测如下碰撞:

                  At the end I create 2 airplanes and make them fly to each other and every iteration I try to detect collision like below:

                  public void detectCollision(){
                      for(Airplane airplane1 : Airplanes){
                          for(Airplane airplane2 : Airplanes){
                              if(Intersector.overlapConvexPolygons(airplane1.getPolygon(), airplane2.getPolygon())){
                                  //COLLISION DON'T HAPPEN!!!
                              }
                      }
                  }
                  

                  我看到两个矩形相互移动并相交,但是 overlapConvexPolygons 函数不起作用!为什么?

                  I see that 2 rectangles move to each other and intersect, but overlapConvexPolygons function doesn't work! Why?

                  推荐答案

                  我已经解决了这个问题.我错误地指定了顶点.我需要得到矩形多边形,所以我不得不使用以下:

                  I've solved this problem. I incorrectly specified vertices. I needed to get rectangular polygon, so I had to use following:

                  polygon = new Polygon(new float[]{0,0,bounds.width,0,bounds.width,bounds.height,0,bounds.height});
                  

                  如果要旋转多边形对象,请不要忘记设置原点:

                  and do not forget set origin if you are going to rotate polygon object:

                  polygon.setOrigin(bounds.width/2, bounds.height/2);
                  

                  现在完美运行了!

                  这篇关于LibGDX - 正确使用多边形类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 libgdx 获取电话语言? 下一篇:LibGDX 3D 提高性能

                  相关文章

                  最新文章

                  <i id='kl0aT'><tr id='kl0aT'><dt id='kl0aT'><q id='kl0aT'><span id='kl0aT'><b id='kl0aT'><form id='kl0aT'><ins id='kl0aT'></ins><ul id='kl0aT'></ul><sub id='kl0aT'></sub></form><legend id='kl0aT'></legend><bdo id='kl0aT'><pre id='kl0aT'><center id='kl0aT'></center></pre></bdo></b><th id='kl0aT'></th></span></q></dt></tr></i><div id='kl0aT'><tfoot id='kl0aT'></tfoot><dl id='kl0aT'><fieldset id='kl0aT'></fieldset></dl></div>
                • <small id='kl0aT'></small><noframes id='kl0aT'>

                  <tfoot id='kl0aT'></tfoot>
                • <legend id='kl0aT'><style id='kl0aT'><dir id='kl0aT'><q id='kl0aT'></q></dir></style></legend>

                      • <bdo id='kl0aT'></bdo><ul id='kl0aT'></ul>