Package playn.core

Class Scale

java.lang.Object
playn.core.Scale

public class Scale extends Object
Encapsulates a scale factor, provides useful utility methods.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final float
    The scale factor for HiDPI mode, or 1 if HDPI mode is not enabled.
    static final Scale
    An unscaled scale factor singleton.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Scale(float factor)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • ONE

      public static final Scale ONE
      An unscaled scale factor singleton.
    • factor

      public final float factor
      The 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

      public List<Scale.ScaledResource> getScaledResources(String path)
      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 to 1. If the native scale factor is 2, this will yield 2, 1. If the native scale factor is 4, this will yield 4, 3, 2, 1. Android devices often have fractional scale factors, which demonstrates the rounding up then back down approach: a native scale factor of 2.5 would yield 2.5, 3, 2, 1.
    • toString

      public String toString()
      Overrides:
      toString in class Object