The Scaler class and its implementations provide different strategies for calculating how a source dimension (e.g., game resolution) should be scaled to fit a target dimension (e.g., screen size).
To use a scaler, call the apply method with the source and target dimensions. The method returns a Vec2f representing the new calculated size.
Available scaling strategies:
Fit: Maintains aspect ratio while fitting as much content as possible onto the screen.Fill: Maintains aspect ratio while ensuring the entire target area is covered (may crop content).FillX: Stretches to fit the target width while maintaining the source aspect ratio.FillY: Stretches to fit the target height while maintaining the source aspect ratio.Stretch: Stretches the content to match the target width and height exactly (ignores aspect ratio).StretchX: Stretches to the target width but keeps the source height.StretchY: Stretches to the target height but keeps the source width.None: Performs no scaling and returns the original source dimensions.
import com.littlekt.util.Scaler
val scaler = Scaler.Fit()
val newSize = scaler.apply(
sourceWidth = 1920,
sourceHeight = 1080,
targetWidth = 1280,
targetHeight = 720
)
println("New Width: ${newSize.x}, New Height: ${newSize.y}")