将Texture2D分配给现有的Texture2D
我目前正在使用 C# XNA 4.0,但在将 Texture2D 分配给现有的 Texture2D 时遇到一些问题。 代码示例如下所示:
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;
但是当我尝试在 etc Draw 中使用 texCurrentDisc 时,出现以下错误: 此方法不接受此参数为 null。 参数名称:纹理。 texCurrentDisc 刚刚初始化为:Texture2D texCurrentDisc;
I am currently messing with C# XNA 4.0, but I am having some problems assigning a Texture2D to an existing 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.
Parameter name: texture.
The texCurrentDisc is just initalized as: Texture2D texCurrentDisc;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这只是代码中的一个错误,纹理在绘制之前初始化得太晚了。
It was simply a mistake in the code, with the texture got initialized too late, before it should draw it.
您可以使用“textures/disc_96”加载纹理吗?我认为它必须使用“textures\disc_96”之类的东西。您还分配给 texDisc48 两次。
所以也许可以尝试:
Can you load the texture using "textures/disc_96"? I thought it had to use something like "textures\disc_96". Also you assign to texDisc48 twice.
So maybe try: