用String加载Texture2D

时间:2016-01-25 14:44:56

标签: c# string xna load texture2d

我正在使用XNA并尝试使用字符串加载图像

image = Game.Content.Load<Texture2D>(playerCharacter.image);

字符类是抽象的,PlayerCharacter类都是从它派生的,图像变量设置为“PlayerSprites / Char1”

运行此代码时出现null异常。路径是正确的,但我不知道路径是否是正确的方法。

1 个答案:

答案 0 :(得分:0)

Don't use the file path. Use the asset name. Click on the asset in the solution explorer. You'll see a bunch of properties pop up. Look at the one that says "Asset Name". That is literally the string you pass in to the loadcontent method. Hope I helped!