简体   繁体   English

将Texture2D分配给现有的Texture2D

[英]Assigning a Texture2D to an existing Texture2D

I am currently messing with C# XNA 4.0, but I am having some problems assigning a Texture2D to an existing Texture2D. 我目前正在使用C#XNA 4.0,但在将Texture2D分配给现有Texture2D时遇到了一些问题。 An example of the code shown below: 下面显示的代码示例:

    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);

        texDisc48 = Content.Load<Texture2D>("textures/disc_24");
        texDisc48 = Content.Load<Texture2D>("textures/disc_48");
        texDisc96 = Content.Load<Texture2D>("textures/disc_96");
    } 
// Random place in the code
texCurrentDisc = texDisc96;

But when I am trying to use the texCurrentDisc in etc Draw, I get the following error: This method does not accept null for this parameter. 但是,当我尝试在etc Draw中使用texCurrentDisc时,出现以下错误: 此方法不为此参数接受null。 Parameter name: texture . 参数名称:texture The texCurrentDisc is just initalized as: Texture2D texCurrentDisc; texCurrentDisc刚被初始化为: Texture2D texCurrentDisc;

这只是代码中的一个错误,因为纹理在绘制之前就初始化得太晚了。

Can you load the texture using "textures/disc_96"? 可以使用“ textures / disc_96”加载纹理吗? I thought it had to use something like "textures\\disc_96". 我认为它必须使用“ textures \\ disc_96”之类的东西。 Also you assign to texDisc48 twice. 您还要两次分配给texDisc48。 So maybe try: 所以也许尝试:

    texDisc24 = Content.Load<Texture2D>("textures\\disc_24");
    texDisc48 = Content.Load<Texture2D>("textures\\disc_48");
    texDisc96 = Content.Load<Texture2D>("textures\\disc_96");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM