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

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

  • <tfoot id='PPkVC'></tfoot>

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

        碰撞后如何使两个物体粘在一起?

        时间:2023-07-27
          <i id='6GfDd'><tr id='6GfDd'><dt id='6GfDd'><q id='6GfDd'><span id='6GfDd'><b id='6GfDd'><form id='6GfDd'><ins id='6GfDd'></ins><ul id='6GfDd'></ul><sub id='6GfDd'></sub></form><legend id='6GfDd'></legend><bdo id='6GfDd'><pre id='6GfDd'><center id='6GfDd'></center></pre></bdo></b><th id='6GfDd'></th></span></q></dt></tr></i><div id='6GfDd'><tfoot id='6GfDd'></tfoot><dl id='6GfDd'><fieldset id='6GfDd'></fieldset></dl></div>
              • <bdo id='6GfDd'></bdo><ul id='6GfDd'></ul>
                <tfoot id='6GfDd'></tfoot>

                <small id='6GfDd'></small><noframes id='6GfDd'>

                    <tbody id='6GfDd'></tbody>

                1. <legend id='6GfDd'><style id='6GfDd'><dir id='6GfDd'><q id='6GfDd'></q></dir></style></legend>
                  本文介绍了碰撞后如何使两个物体粘在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我真的被困在这我可以成功检测到碰撞,但我不能让参与碰撞的两个物体粘在一起.

                  I am really stuck on this I can successfully detect a collision but I can't make the two bodies involved in the collision to stick.

                  这是我的ContactListener

                  world.setContactListener(listener);
                  
                      listener = new ContactListener() {
                  
                          @Override
                          public void preSolve(Contact contact, Manifold oldManifold) {
                  
                          }
                  
                  
                          @Override
                          public void postSolve(Contact contact, ContactImpulse impulse) {
                  
                          }
                  
                          //called when two fixtures cease to touch
                          @Override
                          public void endContact(Contact contact) {
                              Fixture fixtureA = contact.getFixtureA();
                              Fixture fixtureB = contact.getFixtureB();
                              Gdx.app.log("beginContact", "between" + fixtureA.toString() + "and" + fixtureB.toString());
                          }
                  
                          //called when two fixtures begin to touch
                          @Override
                          public void beginContact(Contact contact) {
                              Fixture fixtureA = contact.getFixtureA();
                              Fixture fixtureB = contact.getFixtureB();
                              Gdx.app.log("beginContact", "between" + fixtureA.toString() + "and" + fixtureB.toString());
                          }
                      };
                  

                  这也是我直接在 world.step() 行之后放入我的 render() 的内容

                  Also this is what I put in my render() straight after the world.step() line

                  int numContacts = world.getContactCount();
                  
                      if(numContacts > 0)
                      {
                          Gdx.app.log("contact", "start of contact list");
                          for(Contact contact: world.getContactList())
                          {
                              Fixture fixtureA = contact.getFixtureA();
                              Fixture fixtureB = contact.getFixtureB();
                              Gdx.app.log("contact", "between" + fixtureA.toString() + "and" + fixtureB.toString());
                          }
                          Gdx.app.log("contact", "end of contact list");
                      }
                  

                  我非常困惑于解决后或预解决的问题.我跟着 iforce2d 粘弹 http://www.iforce2d.net/b2dtut/sticky-projectiles 但我不懂 C++,而且在 Eclipse 中工作时遇到很多语法错误.请有人给我看一个工作碰撞的示例代码,请在java中碰撞后身体粘在一起.

                  I am extremely stuck on what to put on post solve or pre-solve really confused. I followed the iforce2d sticky projectiles http://www.iforce2d.net/b2dtut/sticky-projectiles but I don't understand C++ and i get a lot of syntax errors when working in eclipse. Please can someone show me an example code of a working collision where bodies stick together after colliding in java please.

                  推荐答案

                  这就是你如何创建一个 WeldJoint 与 libgdx 包装器:

                  This is how you create a WeldJoint with the libgdx wrapper:

                  WeldJointDef wd = new WeldJointDef();
                  wd.bodyA = body1;
                  wd.bodyB = body2;
                  wd.referenceAngle = wd.bodyB.getAngle() - wd.bodyA.getAngle();
                  world.createJoint( wd );
                  

                  不要尝试在 ContactListener 中创建关节.将要粘合的物体添加到列表中,并在 world.step 之后检查它们.

                  Do not try to create Joints inside the ContactListener. Add the bodies to be glued to a list and check them just after world.step.

                  好的,就像在 iforce2d 教程中一样,创建一个包含 2 个主体的对象:

                  Ok, like in the iforce2d tutorial,create an object to contain 2 bodies:

                  public class StickyInfo{
                      Body bodyA;
                      Body bodyB;
                      public StickyInfo(Body bodyA, Body bodyB){
                          this.bodyA = bodyA;
                          this.bodyB = bodyB;
                      }
                  };
                  

                  然后创建一个 libgdx 数组 StickyInfo 的

                  Then create a libgdx Array of StickyInfo's

                  Array<StickyInfo> collisionsToMakeSticky = new Array<StickyInfo>();
                  

                  当物体发生碰撞时(嗯,从技术上讲,它们的固定装置),将它们添加到此列表中:

                  When the bodies collide (well, technically their fixtures), add them to this list:

                  collisionsToMakeSticky.add(new StickyInfo(body1, body2))
                  

                  然后在 world.step 之后,如果 Array 不为空.创建焊接接头:

                  And then just after world.step, if the Array is not empty. Create the WeldJoints:

                  while(collisionsToMakeSticky.size>0){
                      StickyInfo si = collisionsToMakeSticky.removeIndex(0);
                      //Make the WeldJoint with the bodies si.bodyA and si.bodyB
                  }
                  

                  这篇关于碰撞后如何使两个物体粘在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:iOS的Libgdx项目在模拟器上通过robovm编译时显示l 下一篇:无法为 libgdx 加载共享库 box2d

                  相关文章

                  最新文章

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

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

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