Dave
Dave

Reputation: 23

The type name FromFile does not exist in the type Microsoft.Xna.Framework.Graphics.Texture2D

I was trying to use this well documented function with visual studios 2010 and xna 4.0 and get the error:

The type name FromFile does not exist in the type Microsoft.Xna.Framework.Graphics.Texture2D

With this code:

Texture2D tex1 = Texture2D.FromFile(device, "1.bmp");

Any idea why?

Upvotes: 2

Views: 811

Answers (1)

cHao
cHao

Reputation: 86496

Texture2D.FromFile is a static method that returns you a texture. Your new makes C# look for a type called Texture2D.FromFile (that is, a class inside Texture2D called FromFile).

Drop the new.

EDIT: Seems 4.0 doesn't have Texture2D.FromFile at all. The closest match i see is Texture2D.FromStream, where you'd pass it an open stream to your file rather than its name.

Upvotes: 3

Related Questions