Package playn.core
Class Scale
java.lang.Object
playn.core.Scale
Encapsulates a scale factor, provides useful utility methods.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetScaledResources
(String path) Returns an ordered series of scaled resources to try when loading an asset.float
invScaled
(float length) Returns the supplied length inverse scaled by our scale factor.int
invScaledCeil
(float length) Returns the supplied length inverse scaled by our scale factor and rounded up.int
invScaledFloor
(float length) Returns the supplied length inverse scaled by our scale factor and rounded down.float
roundToNearestPixel
(float length) Rounds the supplied length to the nearest length value that corresponds to an integer pixel length after the scale factor is applied.float
scaled
(float length) Returns the supplied length scaled by our scale factor.int
scaledCeil
(float length) Returns the supplied length scaled by our scale factor and rounded up.int
scaledFloor
(float length) Returns the supplied length scaled by our scale factor and rounded down.toString()
-
Field Details
-
ONE
An unscaled scale factor singleton. -
factor
public final float factorThe scale factor for HiDPI mode, or 1 if HDPI mode is not enabled.
-
-
Constructor Details
-
Scale
public Scale(float factor)
-
-
Method Details
-
scaled
public float scaled(float length) Returns the supplied length scaled by our scale factor. -
scaledCeil
public int scaledCeil(float length) Returns the supplied length scaled by our scale factor and rounded up. -
scaledFloor
public int scaledFloor(float length) Returns the supplied length scaled by our scale factor and rounded down. -
invScaled
public float invScaled(float length) Returns the supplied length inverse scaled by our scale factor. -
invScaledFloor
public int invScaledFloor(float length) Returns the supplied length inverse scaled by our scale factor and rounded down. -
invScaledCeil
public int invScaledCeil(float length) Returns the supplied length inverse scaled by our scale factor and rounded up. -
roundToNearestPixel
public float roundToNearestPixel(float length) Rounds the supplied length to the nearest length value that corresponds to an integer pixel length after the scale factor is applied. For example, for a scale factor of 3, scale.roundToNearestPixel(8.4) = 8.33, which corresponds to exactly (8.33 * 3)= 25 pixels. -
getScaledResources
Returns an ordered series of scaled resources to try when loading an asset. The native resolution will be tried first, then that will be rounded up to the nearest whole integer and stepped down through all whole integers to1
. If the native scale factor is2
, this will yield2, 1
. If the native scale factor is4
, this will yield4, 3, 2, 1
. Android devices often have fractional scale factors, which demonstrates the rounding up then back down approach: a native scale factor of2.5
would yield2.5, 3, 2, 1
. -
toString
-