-1

我正在制作一个 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);   
    }

最好的问候丹尼。

4

1 回答 1

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);   
}
于 2012-05-08T19:08:26.200 回答