我使用Tiled(http://www.mapeditor.org)生成我的地图和TiledSharp(https://github.com/marshallward/TiledSharp)来加载和绘制我的地图。MonoGame + TiledSharp Collision
到目前为止这么好。地图绘制正确(正确的图层)和英雄运动是正确的。
我没有得到。如何检查玩家与物体之间的碰撞?
在我的更新()我有类似
if (ks.IsKeyDown(Keys.W))
{
playerMovement += new Vector2(0, -2);
curAnimation = "Walk_North";
}
...
if (playerMovement.Length() != 0)
player.MoveBy(playerMovement);
检查地图中的.tmx文件,还有就是我的组对象,我可以与碰撞:
<objectgroup name="Collision">
<properties>
<property name="collision" type="bool" value="true"/>
</properties>
<object id="1" x="1089" y="1118" width="62" height="65"/>
<object id="2" x="801" y="1026" width="61" height="60"/>
</objectgroup>
我是什么现在寻找的是类似
If(tileAt(player.Position + playerMovement).Properties.Collision)
playerMovement = Vector2.Zero();
我觉得,一切都是我需要的是有,我只是缺少一个SI多步骤比较球员的位置与目标位置及其属性:(
任何建议或例子,将不胜感激。 (也许只需要通过自己在一个简单的方法来计算的话...)
首先,你不应该添加内绘制的foreach()。在这种情况下,您将每秒60次(@ 60FPS)添加所有collisionObjects,这是非常疯狂的;) 我已经在TileMap构造函数中添加了foreach,因为您需要每个地图只填充一次碰撞对象(假设您加载地图一次) 第二个: 请检查您的.tmx文件中的以下内容 等等 objectgroup> 组是区分大小写的! –