C# 与sourceRectangle monogame一起使用float
我尝试将缩放与monogame一起使用,为此,我也修改了hitbox的sourceRectangle,但当我尝试为sourceRectangle指定0.5的缩放比例时,宽度和高度=0 因为我的结石是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 感谢您的帮助我真的不知道您
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);