【问题标题】:Use float with sourceRectangle monogame将浮点数与 sourceRectangle 单体游戏一起使用
【发布时间】:2018-05-29 08:41:13
【问题描述】:

我尝试在monogame中使用比例,为此我也修改了hitbox的sourceRectangle,但是当我尝试分配0.5来缩放sourceRectangle.Width和Height = 0

因为我的计算是

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

感谢您的帮助

【问题讨论】:

    标签: c# monogame


    【解决方案1】:

    在我看来,你的选角放错了地方。比例在乘以之前会四舍五入为零。

    试试这个:

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

    【讨论】:

      【解决方案2】:

      我真的不知道你的sourceRectangle 是什么类型,但我猜它的Microsoft.Xna.Framework.Rectangle 使用Int32 作为其成员。Source

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

      您可以自己编译 MonoGame 并为自己编写一个 floaty-Rectangle 结构体,可以将其赋予 SpriteBatch 并且您可以特别修改此方法,因为它无论如何都使用 float:Draw in SpriteBatch

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-09
        • 1970-01-01
        • 2011-04-30
        • 2018-10-01
        • 2020-04-21
        相关资源
        最近更新 更多