Texture2D作为Class构造函数的参数

时间:2012-05-08 19:05:01

标签: c# xna-4.0

我正在创建一个Level.cs类,它应该将背景图像(texture2d)作为Level类构造函数的参数。但是它不会接受变量'back'。我该怎么做?

    public Level(Texture2D back ,ContentManager content, EventHandler ScreenEvent, Microsoft.Xna.Framework.Game game) : base(ScreenEvent)
    {
        background = content.Load<Texture2D>(back);
        backgroundVector = new Vector2(-1150, 0);
        velocity = 5.0f;
        ground = 508;
        graphics = new GraphicsDeviceManager(game);   
    }

最好的问候丹尼。

1 个答案:

答案 0 :(得分:3)

您是否尝试从纹理加载纹理?

您可以将“Texture2D”重命名为字符串

 public Level(String back ,ContentManager content, EventHandler ScreenEvent, Microsoft.Xna.Framework.Game game) : base(ScreenEvent)
{
    background = content.Load<Texture2D>(back);
    backgroundVector = new Vector2(-1150, 0);
    velocity = 5.0f;
    ground = 508;
    graphics = new GraphicsDeviceManager(game);   
}

或只是做

 public Level(Texture2D back ,ContentManager content, EventHandler ScreenEvent, Microsoft.Xna.Framework.Game game) : base(ScreenEvent)
{
    background = back;
    backgroundVector = new Vector2(-1150, 0);
    velocity = 5.0f;
    ground = 508;
    graphics = new GraphicsDeviceManager(game);   
}