如何将纹理加载到 XNA?
好吧,所以我需要为我正在制作的游戏提供纹理,并且我找到了适合我的项目的纹理(某种球)。该纹理位于其他纹理旁边(纹理表)。 所以我必须下载所有的表格。现在,我只需要获得我想要的纹理(那个球)。我只能用一个矩形圈住它(使用 Paint)。难道XNA真的有无知之色吗?或者还有其他方法可以只加载我的球吗?而不是背景呢?
拜托,我真的需要一个答案..非常感谢。
Alright, so I need a texture for a game that I'm making and I found a texture that fit to my project(some kind of ball). The texture is next to other textures(Textures sheet).
So I had to download all the sheet. Now, I need to get only the texure that I want (that ball). And I can only circle it by a rectangle(using Paint). Is it true that XNA has an ignorant color? Or there's any other way that I can load ONLY MY BALL? and not the background of it?
Please, I really need an answer for it.. Thanks alot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要启用色键透明度,请在内容项目中选择纹理,然后按 F4 打开属性窗口。展开“内容处理器”选项以显示颜色键设置。打开颜色键并选择合适的颜色。
如果您需要在 XNA 中使用精灵表(即:如果您不在图像编辑器中裁剪它),则可以使用
SpriteBatch.Draw
的sourceRectangle
参数仅将源纹理的特定矩形区域视为精灵。默认情况下
SpriteBatch
将使用BlendState.AlphaBlend
进行绘制(即:如果您使用Begin()
重载,则无需设置它),这将为您正确处理透明度。To enable colour-key transparency, select your texture in your content project and press F4 to bring up the properties window. Expand the "Content Processor" option to reveal the colour key settings. Turn on colour key and select the appropriate colour.
If you need to use a sprite sheet within XNA (ie: if you're not cropping it in your image editor), you can use the
sourceRectangle
parameter toSpriteBatch.Draw
to treat only a particular rectangular region of your source texture as a sprite.By default
SpriteBatch
will draw withBlendState.AlphaBlend
(ie: if you use theBegin()
overload, you don't need to set it), which will correctly handle the transparency for you.