在 XNA 中调整大小并加载texture2d

发布于 2024-10-06 02:54:08 字数 402 浏览 3 评论 0原文

我是 XNA 的新手,以防万一。我尝试做的是加载与原始大小不同的纹理,或者至少有可能在之后更改他的大小。我在一些地方看到我可以使用:

Texture2D.FromStream(GraphicsDevice graphicsDevice, Stream stream, 
                 int width, int height, bool zoom)

但我也读到以这种方式加载纹理会忽略 ContentManager,并且我使垃圾收集器的工作变得更加困难。

使用 ContentManager 加载任何尺寸的图像的正确方法是什么? 如果这不可能,我可以按比例改变他的大小,比如使用变焦吗?

语境: 我正在创建一个 nxn 和平委员会。当 n 太大时,我需要自动变得更小。

i'm a newbie in XNA just in case. What i try to do is load a texture in a different size from his original, or at least have the possibility to change his size after. I see in some places that i can use:

Texture2D.FromStream(GraphicsDevice graphicsDevice, Stream stream, 
                 int width, int height, bool zoom)

But i also read that loading textures in this way is ignoring the ContentManager, and that i'm making the job for the garbage collector more difficult.

What is the Correct way to load an image in any size, using the ContentManager ?
If that isn't possible can i change his size proportionally, like using a zoom?

Context:
I'm creating a board of n x n peaces. When n is too big i need that automatically the peaces becomes more smaller.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃酥萝莉 2024-10-13 02:54:08

加载纹理:

Texture2D tex = Content.Load<Texture2D>("somefile");

要调整其大小,请使用采用“scale”的 SpriteBatch 重载之一
http://msdn.microsoft.com /en-us/library/microsoft.xna.framework.graphics.spritebatch.draw.aspx

float scale = .5f; //50% smaller
SpriteBatch.Draw(tex, position, source, Color.White, rotation, scale, SpriteEffects.None, 0f);

如果您是 XNA 新手,我建议您阅读 这个简短教程,并查看 教育目录,位于 create.msdn.com

To load the texture:

Texture2D tex = Content.Load<Texture2D>("somefile");

To resize it use one of the SpriteBatch overloads that takes "scale"
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.draw.aspx

float scale = .5f; //50% smaller
SpriteBatch.Draw(tex, position, source, Color.White, rotation, scale, SpriteEffects.None, 0f);

If you are new to XNA, I suggest you read this short tutorial, and also check out Education Catalog at create.msdn.com

魔法唧唧 2024-10-13 02:54:08
Texture2D texture;
protected override void LoadContent()
        {
...
         texture = Content.Load<Texture2D>("Tank");
...
        }
protected override void Draw(GameTime gameTime)
        {
...
         Rectangle destinationRectangle = new Rectangle(100, 100, 30, 10);
         spriteBatch.Draw(texture, destinationRectangle, Color.White);
...
         spriteBatch.End();
         base.Draw(gameTime);
        }
Texture2D texture;
protected override void LoadContent()
        {
...
         texture = Content.Load<Texture2D>("Tank");
...
        }
protected override void Draw(GameTime gameTime)
        {
...
         Rectangle destinationRectangle = new Rectangle(100, 100, 30, 10);
         spriteBatch.Draw(texture, destinationRectangle, Color.White);
...
         spriteBatch.End();
         base.Draw(gameTime);
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文