我使用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> 組是區分大小寫的! –