2011-05-08 125 views
0

這裏界面MOF我的代碼的一部分:問題與XNA遊戲項目

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Graphics; 
using Microsoft.Xna.Framework.Content; 

. 
. 
. 

    public virtual bool CheckCollision(ICollidable i_Source) 
    { 
     bool collided = false; 
     ICollidable2D source = i_Source as 2DICollidable; 
     if (source != null) 
     { 
      collided = source.Bounds.Intersects(this.Bounds); 
     } 

     return collided; 
    } 

出於某種原因,有關於使用ICollided2D錯誤。 它爲什麼不識別這種變量?我錯過任何「使用」的說法嗎?

+1

你應該更精確。什麼是你收到的錯誤信息? – Patrik 2011-05-08 09:12:43

+1

你的意思是編譯錯誤? (在嘗試編譯代碼時收到),或實際執行時發生運行時錯誤? – 2011-05-08 13:10:42

回答

1

2DICollidable

這是什麼?我不認爲普通標識符可以以數字開頭。甚至是SO代碼高亮顯示紅色。

2

無論這是打錯了:

ICollidable2D source = i_Source as 2DICollidable;

或者你缺少一個2DICollidable_,因此它成爲_2DICollidable,你不能以數字開頭的標識符。