2012-11-27 130 views
0

我想弄清楚瓷磚碰撞,我不能得到這個工作。當我與瓷磚碰撞時,什麼也沒有發生。XNA資源錯誤

我的碰撞類

public Point WorldToMapCell(Point worldPoint) 
    { 
     return new Point((int)worldPoint.X, (int)worldPoint.Y); 
    } 

    public MapCell GetCellAtWorldPoint(Point worldPoint) 
    { 
     Point mapPoint = WorldToMapCell(worldPoint); 
     return Rows[mapPoint.Y].Columns[mapPoint.X]; 
    } 

    public MapCell GetCellAtWorldPoint(Vector2 worldPoint) 
    { 
     return GetCellAtWorldPoint(new Point((int)worldPoint.X, (int)worldPoint.Y)); 
    } 

我的更新方法

 if (myMap.GetCellAtWorldPoint(player.position).Walkable == false) 
     { 
      player.velocity = Vector2.Zero; 
     } 
+1

Your WorldToMapCell()函數什麼都不做。它只是返回您傳入的相同Point對象。 – jgallant

回答

0

我真的不知道你的工作是什麼樣的遊戲。

但是你真的需要檢查地圖上的位置嗎?或者與collision_2d_perpixel method解決方案不會更好?

如果碰撞2D方法不是很好,那麼您對碰撞類更加期待嗎? 你的參考地圖在哪裏?你什麼時候不得不說「我在碰撞?」

你可以看看這個鏈接dreamincode user problem並告訴我們這是不是你要找的?

或者你甚至可以看看MSDN