Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 与sourceRectangle monogame一起使用float_C#_Monogame - Fatal编程技术网

C# 与sourceRectangle monogame一起使用float

C# 与sourceRectangle monogame一起使用float,c#,monogame,C#,Monogame,我尝试将缩放与monogame一起使用,为此,我也修改了hitbox的sourceRectangle,但当我尝试为sourceRectangle指定0.5的缩放比例时,宽度和高度=0 因为我的结石是 sourceRectangle.Width = (texture.Width / cols) * (int)this.scale.X sourceRectangle.Height = (texture.Height / rows) * (int)this.scale.Y 感谢您的帮助我真的不知道您

我尝试将缩放与monogame一起使用,为此,我也修改了hitbox的sourceRectangle,但当我尝试为sourceRectangle指定0.5的缩放比例时,宽度和高度=0

因为我的结石是

sourceRectangle.Width = (texture.Width / cols) * (int)this.scale.X
sourceRectangle.Height = (texture.Height / rows) * (int)this.scale.Y

感谢您的帮助

我真的不知道您的
源矩形
是什么类型,但我猜它的
Microsoft.Xna.Framework.Rectangle
,它的成员使用
Int32

如果希望纹理具有
0.5f
,可以将纹理缩放2,然后不必获得任何“一半”值。但除此之外,如果不修改
SpriteBatch
,就没有实物期权


您可以为自己编译MonoGame,并为自己编写一个floaty-
矩形
结构,该结构可以提供给
SpriteBatch
,并且您可以特别修改此方法,因为它使用float:

在我看来,您的施法位置不正确。在倍增之前,比例将被舍入为零

请尝试以下方法:

sourceRectangle.Width = (int)((texture.Width / cols) * this.scale.X);
sourceRectangle.Height = (int)((texture.Height / rows) * this.scale.Y);