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

      <legend id='mVkVf'><style id='mVkVf'><dir id='mVkVf'><q id='mVkVf'></q></dir></style></legend>
      1. <small id='mVkVf'></small><noframes id='mVkVf'>

      2. <tfoot id='mVkVf'></tfoot>
      3. 使用 TiledMap 的 Libgdx 碰撞检测

        时间:2023-05-19
          <tbody id='r5lk6'></tbody>

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

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

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

                • <legend id='r5lk6'><style id='r5lk6'><dir id='r5lk6'><q id='r5lk6'></q></dir></style></legend>
                  本文介绍了使用 TiledMap 的 Libgdx 碰撞检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在努力通过平铺地图实现碰撞检测系统.我有一个渲染了平铺地图的 2d口袋妖怪风格"游戏.具体来说,我的平铺地图 .tmx 文件中有一个碰撞"层,我想与玩家和其他实体进行交互.我的问题是如何将玩家精灵(扩展 Sprite 类)连接到平铺地图的碰撞"层并导致两者之间发生碰撞.任何建议表示赞赏.

                  I'm struggling with implementing a collision detection system through the tiledmap. I have a 2d "pokemon style" game that has a tiled map rendered. Specifically, I have a 'collision' layer in my tiled map .tmx file that I want to interact with the player and other entities. My question is how do I connect the player sprite (extends Sprite class) to the 'collision' layer of the tiledmap and cause collision between the two. Any advice is appreciated.

                  推荐答案

                  首先你的Player可能不应该extend Sprite,因为你的播放器通常比精灵.它可能由几个精灵甚至 Animations 组成.将精灵保留为玩家的属性.

                  First of all your Player should probably not extend Sprite, because your player is usually much more than a Sprite. It probably consists of several sprites or even Animations. Keep a sprite as a property of the player.

                  这个问题本身已经讨论过好几次了.您通常需要以下步骤:

                  The question itself has already been adressed several times. You usually need the following steps:

                  1. 在地图中查找碰撞层
                  2. 从该层中提取所有对象
                  3. 检查每个对象是否发生碰撞

                  在代码中可能有点像这样:

                  In code this might look a bit like this:

                  int objectLayerId = 5;
                  TiledMapTileLayer collisionObjectLayer = (TiledMapTileLayer)map.getLayers().get(objectLayerId);
                  MapObjects objects = collisionObjectLayer.getObjects();
                  
                  // there are several other types, Rectangle is probably the most common one
                  for (RectangleMapObject rectangleObject : objects.getByType(RectangleMapObject.class)) {
                  
                      Rectangle rectangle = rectangleObject.getRectangle();
                      if (Intersector.overlaps(rectangle, player.getRectangle()) {
                          // collision happened
                      }
                  }
                  

                  更多您可能感兴趣的链接:

                  Some more links which you might be interested in:

                  • Java 平铺地图游戏 (LibGDX) |第 4 集 - 碰撞检测
                  • Java 平铺地图游戏 (LibGDX) |第 4 集更新 - 更好的碰撞检测实现
                  • Android 游戏开发与 libgdx – 碰撞检测,第 4 部分
                  • SuperKoalio 示例游戏使用 TiledMaps 和碰撞

                  这篇关于使用 TiledMap 的 Libgdx 碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么我在使用 Tiled 的 libgdx 游戏中出现线条? 下一篇:如何使用 libgdx 中的简单纹理绘制自定义形状?

                  相关文章

                  最新文章

                  <tfoot id='92TOQ'></tfoot>

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

                  1. <legend id='92TOQ'><style id='92TOQ'><dir id='92TOQ'><q id='92TOQ'></q></dir></style></legend>

                    <small id='92TOQ'></small><noframes id='92TOQ'>

                      <bdo id='92TOQ'></bdo><ul id='92TOQ'></ul>