为什么Vector2(来自XNA的库)使用float而不是int?

pat*_*eza 3 floating-point int xna draw spritebatch

为什么Vector2(来自XNA的库)使用float而不是int

计算机屏幕上的位置以像素给出,以便光标位置可以由两个整数定义.没有半像素这样的东西.为什么我们使用花车呢?

SpriteBatch类中,我发现了7个名为Draw的重载方法.他们两个人:

public void Draw(Texture2D texture, Rectangle destinationRectangle, Color color);
public void Draw(Texture2D texture, Vector2 position, Color color);
Run Code Online (Sandbox Code Playgroud)

所以我们可以看到Draw同时接受intfloat坐标.

当我实现游戏对象的屏幕坐标时,我遇到了这个问题.我认为Rectangle是保存对象大小和屏幕坐标的不错选择.但现在我不确定......

Dav*_*eau 5

在数学上,向量是运动,而不是位置.虽然屏幕上的位置在技术上可能无法在整数之间进行,但动作肯定可以.如果使用的矢量int是最慢的,那么你可以移动(1, 1).使用floats,你可以移动(.1, .1),(.001, .001)等等.

(另请注意,XNA结构Point实际上使用了ints.)