Rectangle is an ambiguous reference error

Dec 19, 2012 at 6:05 PM
Edited Dec 19, 2012 at 6:14 PM

I recently started using tide to make a simple game. When I try to do the animation I get thrown this error "Rectangle is an ambiguous reference between "microsoft.xna.framework.rectangle" and xTile.Dimensions.Rectangle. I'm just not grasping this tile engine so I have no idea how to fix,

I tried to do something like (using rectangle = Microsoft.Xna.Framework.Rectangle;) but it doesnt seem to work, and ideas on how to fix this problem?


EDIT: solved, had to include the namespace in the name. sucks that I may have to do this over an over lol

Dec 20, 2012 at 9:28 AM

You could opt to only import one namespace, typically the one you use most often. Then you just need to fully qualify the Rectangle for the namespace you didn't import.

Jun 20, 2013 at 7:05 PM
I'm also getting this error and despite above answer can't seem to implement correctly.
I'm a complete noob so any help would be massively appreciated.
My animation works perfectly before I implement the map then error message occurs.
Jun 20, 2013 at 9:01 PM
Edited Jun 20, 2013 at 9:07 PM
xTile defines a type called Rectangle which conflicts with a Rectangle type defined in XNA. If you import both the namespaces Microsoft.Xna.Framework and xTile.Dimensions at the top of your code files (which contain the respective Rectangle types), then the compiler doesn't know which Rectangle you mean, unless you fully qualify it with the namespace.

So basically, instead of declaring your rectangle as
Rectangle myRectangle = new Rectangle(...);
use the full type qualifier xTile.Dimensions.Rectangle as in
xTile.Dimensions.Rectangle myRectangle = new xTile.Dimensions.Rectangle(...);
If you want to use the XNA one instead, you need to specify it as Microsoft.Xna.Framework.Rectangle.

I hope that helps. Beyond this, I think you should look up some C# tutorials.
Jun 21, 2013 at 6:57 PM
Massive help.
Thank You!!