RoundFloat
Introduction
Code Example
using FlatRedBall.Math;float valueToRound = 2.1f;
// Notice that multipleOf does not have to be a whole number:
float multipleOf = .481f;
float result = MathFunctions.RoundFloat(valueToRound, multipleOf);
// result will equal 1.924, which is .481 * 4.Code Example: Using RoundFloat for even-spacing index
const float startingY = 10;
const float spacingBetweenButtons = 35;
// Assume worldY is the Y value that you want to convert to an index
float indexAsFloat = MathFunctions.RoundFloat(worldY, spacingBetweenButtons, startingY);
// Now we can convert this to an int
int index = MathFunctions.RoundToInt(indexAsFloat);Code Example: Using RoundFloat to Adjust Camera Offsets
Last updated
Was this helpful?