Search code examples
c#monogame

Use float with sourceRectangle monogame


I try use the scale with monogame and for this I modify the sourceRectangle too for the hitbox but when I'm trying to assign 0.5 for scale the sourceRectangle.Width and Height = 0

because my calcul is

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

Thanks for your help


Solution

  • It looks to me like you've got your casting in the wrong place. The scale is getting rounded down to zero before it gets multiplied.

    Try this instead:

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