XNA 如何让 xna 不读取透明色 [英] XNA How to make xna not to read transparent color

查看:33
本文介绍了XNA 如何让 xna 不读取透明色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 xna 相当陌生.我刚刚创建了一个透明背景(洋红色)的精灵.问题是我的矩形正在读取整个精灵的坐标而不是可见的精灵.如何让它只读取可见的精灵.

I am fairly new to xna. I just created a sprite with transparent background(magenta). Problem is my Rectangle is reading the coordinates of whole sprite not of visible one. How do I make it read only the visible sprite.

myrectangle = new Rectangle(0, 0, box.Width, box.Height);

我想将不透明的可见部分放置在该位置.提前致谢.

I want to place my visible part not transparent at that position. Thanks in advance.

推荐答案

要将颜色转换为透明,请转到纹理属性、内容处理器,并启用 Color Key,并将关键 Color 设置为洋红色.

To transform a color to transparent, go to the texture properties, content processor, and enable Color Key, and set the key Color to magenta.

然后要将精灵定位在您想要的位置,您需要设置正确的原点.

Then to positioning the sprite where you want, you need to set the proper origin.

要将船舶中心设置在所需位置,需要设置原点,如图所示:

To set the ship center in the desired position, is needed to set the origin as shown:

所以当你绘制它时,你需要做类似的事情:

So when you draw it, you need doing similar to this:

 var origin = new Vector2(40,40);
 spritebatch.Draw(shipTexture, shipPosition, null, Color, origin, ...)

您也可以更改纹理矩形源:

You can change your texture rectangle source too:

 var texSource = new Rectangle( 25,25, 30,30);
 spritebatch.Draw(shipTexture, shipPosition, texSource, Color)

虽然如果你想把船定位在它的中心,你可能需要改变原点

Although you may need to change the origin if you want to position the ship at its center

这篇关于XNA 如何让 xna 不读取透明色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆