<tfoot id='V4XQc'></tfoot>
    1. <small id='V4XQc'></small><noframes id='V4XQc'>

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

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

      1. <legend id='V4XQc'><style id='V4XQc'><dir id='V4XQc'><q id='V4XQc'></q></dir></style></legend>
      2. MouseJointDef libgdx - 像愤怒的小鸟一样画一条轨迹线

        时间:2023-05-20
        <tfoot id='qbEtr'></tfoot>
            <tbody id='qbEtr'></tbody>
            • <bdo id='qbEtr'></bdo><ul id='qbEtr'></ul>

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

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

                • 本文介绍了MouseJointDef libgdx - 像愤怒的小鸟一样画一条轨迹线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  在 libgdx 游戏中

                  in libgdx game

                  我想 touchDown 然后拖动某处,然后在释放 (touchUp) 时根据与目标主体的距离和方向施加方向力.当您触地时,目标身体保持静止,然后在触地时沿所需轨迹施加力.

                  I want to touchDown and then drag somewhere and then on the release (touchUp) apply a directional force based on the distance and direction from the target body. When you touchdown the target body stays still and then on touchup the force is applied along the desired trajectory.

                  (非常类似于愤怒的小鸟——当你拿着弹弓时,你可以看到目标身体的虚线轨迹——我也想这样做)

                  (very similar to Angry birds - where you get to see the trajectory in dotted lines for the target body when you hold hack the slingshot - I want to do the same)

                  所以我想这可能不是最难做的事情,但考虑到一些选项,我倾向于使用 MouseJointDef,但它会立即施加力(即目标立即移动 - 我希望它保持静止,然后一旦touchup 事件发生然后施加力)

                  So I guess that this might not be the hardest thing to do but given a few options Im leaning towards using a MouseJointDef but its an immediate force applied (i.e. the target moves immediately - I want it to stay still and then once the touchup event happens then apply the force)

                  绘制轨迹最简单的方法是什么?我也在使用 Box2D.

                  Whats the easiest way to draw the trajectory also? Im using Box2D also.

                  推荐答案

                  创建一个继承 InputAdapter 类的类,然后创建它的一个实例并注册它来监听触摸输入.

                  Create a class that inherits InputAdapter class, then create an instance of it and register it to listen the touch inputs.

                      Gdx.input.setInputProcessor(inputAdapter);
                  

                  有 3 种方法可以处理您必须覆盖的触摸事件 touch_downtouch_draggedtouch_up.

                  There are 3 methods to handle the touch events touch_down, touch_dragged and touch_up that you have to override.

                  touch_down中,检查触摸位置是否在鸟区.如果是,则将布尔标志设为 true.

                  In touch_down, check the touching position to whether is in the birds area or not. If it is, make a boolean flag true.

                  touch_dragged中,检查上面的flag,如果为真,计算touch位置相对于小鸟射击中心的距离和射击角度.

                  In touch_dragged, check the flag above and if it was true, calculate the distance of the touch position relative to the bird shooting center and the shooting angle.

                  touch_up中,您可以通过调用来订购计算的数量进行拍摄

                  In touch_up, you can order to shoot with the calculated amounts by calling

                      body2shoot.applyLinearImpulse(impulse, body2shoot.getWorldCenter());
                  

                  不需要MouseJointDef来移动body2shoot.只需将 body2shoot 的变换设置在触摸位置,以便在每个渲染周期中拖动即可.

                  There is no need to MouseJointDef to move the body2shoot. Just set the transform of body2shoot in touching position to be dragged in each cycle of render.

                  为了计算轨迹,我写了一个这样的类:

                  For calculating the trajectory I wrote a class like this:

                  public class ProjectileEquation
                  {
                  public float gravity;
                  public Vector2 startVelocity = new Vector2();
                  public Vector2 startPoint = new Vector2();
                  
                  public ProjectileEquation()
                  {   }
                  
                  public float getX(float t)
                  {
                      return startVelocity.x*t + startPoint.x;
                  }
                  
                  public float getY(float t)
                  {
                      return 0.5f*gravity*t*t + startVelocity.y*t + startPoint.y;
                  }
                  }
                  

                  为了绘制它,我设置了 startPointstartVelocity 然后在循环中我逐步给出一个 t (时间)并调用getX(t)getY(t).

                  and for drawing it just I set the startPoint and startVelocity and then in a loop I give a t (time) incrementally and call getX(t) and getY(t).

                  这篇关于MouseJointDef libgdx - 像愤怒的小鸟一样画一条轨迹线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:LibGDX:粒子尺度 下一篇:如何使 libGDX 桌面应用程序可调整大小?

                  相关文章

                  最新文章

                  <legend id='SoMbP'><style id='SoMbP'><dir id='SoMbP'><q id='SoMbP'></q></dir></style></legend>

                      <tfoot id='SoMbP'></tfoot>
                      • <bdo id='SoMbP'></bdo><ul id='SoMbP'></ul>
                    1. <small id='SoMbP'></small><noframes id='SoMbP'>

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