Class/Object

io.scalajs.dom.html.phaser

Math

Related Docs: object Math | package phaser

Permalink

class Math extends Object

A collection of useful mathematical functions. These are normally accessed through game.math.

Annotations
@RawJSType() @native() @JSName( "Phaser.Math" )
See also

io.scalajs.dom.html.phaser.utils.Utils

io.scalajs.dom.html.phaser.utils.ArrayUtils

https://phaser.io/docs/2.6.2/Phaser.Math.html

Linear Supertypes
Object, Any, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Math
  2. Object
  3. Any
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Math()

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def PI2: Double

    Permalink

    Twice PI.

  5. def angleBetween(x1: Double, y1: Double, x2: Double, y2: Double): Double

    Permalink

    Find the angle of a segment from (x1, y1) -> (x2, y2).

    Find the angle of a segment from (x1, y1) -> (x2, y2).

    x1

    The x coordinate of the first value.

    y1

    The y coordinate of the first value.

    x2

    The x coordinate of the second value.

    y2

    The y coordinate of the second value.

    returns

    The angle, in radians.

  6. def angleBetweenPoints(point1: Phaser.Point, point2: Phaser.Point): Double

    Permalink

    Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y).

    Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y).

    point1

    The first point.

    point2

    The second point.

    returns

    The angle between the two points, in radians.

  7. def angleBetweenPointsY(point1: Phaser.Point, point2: Phaser.Point): Double

    Permalink

    Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y).

    Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y).

    point1

    The first point.

    point2

    The second point.

    returns

    The angle, in radians.

  8. def angleBetweenY(x1: Double, y1: Double, x2: Double, y2: Double): Double

    Permalink

    Find the angle of a segment from (x1, y1) -> (x2, y2).

    Find the angle of a segment from (x1, y1) -> (x2, y2). The difference between this method and Math.angleBetween is that this assumes the y coordinate travels down the screen.

    x1

    The x coordinate of the first value.

    y1

    The y coordinate of the first value.

    x2

    The x coordinate of the second value.

    y2

    The y coordinate of the second value.

    returns

    The angle, in radians.

  9. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  10. def average(): Double

    Permalink

    Averages all values passed to the function and returns the result.

    Averages all values passed to the function and returns the result.

    returns

    The average of all given values.

  11. def between(min: Double, max: Double): Double

    Permalink

    Returns a number between the min and max values.

    Returns a number between the min and max values.

    min

    The minimum value. Must be positive, and less than 'max'.

    max

    The maximum value. Must be position, and greater than 'min'.

    returns

    A value between the range min to max.

  12. def bezierInterpolation(v: Array[JsNumber], k: Double): Double

    Permalink

    A Bezier Interpolation Method, mostly used by Phaser.Tween.

    A Bezier Interpolation Method, mostly used by Phaser.Tween.

    v

    The input array of values to interpolate between.

    k

    The percentage of interpolation, between 0 and 1.

    returns

    The interpolated value

  13. def catmullRomInterpolation(v: Array[JsNumber], k: Double): Double

    Permalink

    A Catmull Rom Interpolation Method, mostly used by Phaser.Tween.

    A Catmull Rom Interpolation Method, mostly used by Phaser.Tween.

    v

    The input array of values to interpolate between.

    k

    The percentage of interpolation, between 0 and 1.

    returns

    The interpolated value

  14. def ceilTo(value: JsNumber, place: JsNumber = js.native, base: JsNumber = js.native): Double

    Permalink

    Ceils to some place comparative to a base, default is 10 for decimal place.

    Ceils to some place comparative to a base, default is 10 for decimal place. The place is represented by the power applied to base to get that place.

    value

    The value to round.

    place

    The place to round to.

    base

    The base to round in. Default is 10 for decimal.

    returns

    The rounded value.

  15. def clamp(v: Double, min: Double, max: Double): Double

    Permalink

    Force a value within the boundaries by clamping it to the range min, max.

    Force a value within the boundaries by clamping it to the range min, max.

    v

    The value to be clamped.

    min

    The minimum bounds.

    max

    The maximum bounds.

    returns

    The clamped value.

  16. def clampBottom(x: Double, a: Double): Double

    Permalink

    Clamp x to the range [a, Infinity).

    Clamp x to the range [a, Infinity). Roughly the same as Math.max(x, a), except for NaN handling.

    x

    TODO

    a

    TODO

    returns

    a number

  17. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. def degToRad(degrees: Double): Double

    Permalink

    Convert degrees to radians.

    Convert degrees to radians.

    degrees

    Angle in degrees.

    returns

    Angle in radians.

  19. def difference(a: Double, b: Double): Double

    Permalink

    The absolute difference between two values.

    The absolute difference between two values.

    a

    The first value to check.

    b

    The second value to check.

    returns

    The absolute difference between the two values.

  20. def distance(x1: Double, y1: Double, x2: Double, y2: Double): Double

    Permalink

    Returns the euclidian distance between the two given set of coordinates.

    Returns the euclidian distance between the two given set of coordinates.

    x1

    The x coordinate of the first value.

    y1

    The y coordinate of the first value.

    x2

    The x coordinate of the second value.

    y2

    The y coordinate of the second value.

    returns

    The distance between the two sets of coordinates.

  21. def distancePow(x1: Double, y1: Double, x2: Double, y2: Double, pow: Double = js.native): Double

    Permalink

    Returns the distance between the two given set of coordinates at the power given.

    Returns the distance between the two given set of coordinates at the power given.

    x1

    The x coordinate of the first value.

    y1

    The y coordinate of the first value.

    x2

    The x coordinate of the second value.

    y2

    The y coordinate of the second value.

    pow

    optional: exponent

    returns

    The distance between the two sets of coordinates.

  22. def distanceSq(x1: Double, y1: Double, x2: Double, y2: Double): Double

    Permalink

    Returns the euclidean distance squared between the two given set of coordinates (cuts out a square root operation before returning).

    Returns the euclidean distance squared between the two given set of coordinates (cuts out a square root operation before returning).

    x1

    The x coordinate of the first value.

    y1

    The y coordinate of the first value.

    x2

    The x coordinate of the second value.

    y2

    The y coordinate of the second value.

    returns

    The distance squared between the two sets of coordinates.

  23. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  24. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  25. def factorial(value: Double): Double

    Permalink

    Computes the factorial of the given value

    Computes the factorial of the given value

    value

    the number you want to evaluate

    returns

    the factorial value

  26. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  27. def floorTo(value: Double, place: Double, base: Double): Double

    Permalink

    Floors to some place comparative to a base, default is 10 for decimal place.

    Floors to some place comparative to a base, default is 10 for decimal place. The place is represented by the power applied to base to get that place.

    value

    The value to round.

    place

    The place to round to.

    base

    The base to round in. Default is 10 for decimal.

    returns

    The rounded value.

  28. def fuzzyCeil(value: Double, epsilon: Double): Double

    Permalink

    Applies a fuzzy ceil to the given value.

    Applies a fuzzy ceil to the given value.

    value

    The value to ceil.

    epsilon

    The epsilon (a small value used in the calculation)

    returns

    ceiling(value - epsilon)

  29. def fuzzyEqual(a: Double, b: Double, epsilon: Double): Boolean

    Permalink

    Two number are fuzzyEqual if their difference is less than epsilon.

    Two number are fuzzyEqual if their difference is less than epsilon.

    a

    The first number to compare.

    b

    The second number to compare.

    epsilon

    The epsilon (a small value used in the calculation)

    returns

    True if | a-b | < epsilon

  30. def fuzzyFloor(value: Double, epsilon: Double): Double

    Permalink

    Applies a fuzzy floor to the given value.

    Applies a fuzzy floor to the given value.

    value

    The value to floor.

    epsilon

    The epsilon (a small value used in the calculation)

    returns

    floor(value + epsilon)

  31. def fuzzyGreaterThan(a: Double, b: Double, epsilon: Double): Boolean

    Permalink

    a is fuzzyGreaterThan b if it is more than b - epsilon.

    a is fuzzyGreaterThan b if it is more than b - epsilon.

    a

    The first number to compare.

    b

    The second number to compare.

    epsilon

    The epsilon (a small value used in the calculation)

    returns

    True if a > b + epsilon

  32. def fuzzyLessThan(a: Double, b: Double, epsilon: Double): Boolean

    Permalink

    a is fuzzyLessThan b if it is less than b + epsilon.

    a is fuzzyLessThan b if it is less than b + epsilon.

    a

    The first number to compare.

    b

    The second number to compare.

    epsilon

    The epsilon (a small value used in the calculation)

    returns

    True if a < b + epsilon

  33. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  34. def getShortestAngle(angle1: Double, angle2: Double): Double

    Permalink

    Gets the shortest angle between angle1 and angle2.

    Gets the shortest angle between angle1 and angle2. Both angles must be in the range -180 to 180, which is the same clamped range that sprite.angle uses, so you can pass in two sprite angles to this method, and get the shortest angle back between the two of them. The angle returned will be in the same range. If the returned angle is greater than 0 then it's a counter-clockwise rotation, if < 0 then it's a clockwise rotation.

    angle1

    The first angle. In the range -180 to 180.

    angle2

    The second angle. In the range -180 to 180.

    returns

    The shortest angle, in degrees. If greater than zero it's a counter-clockwise rotation.

  35. def hasOwnProperty(v: String): Boolean

    Permalink
    Definition Classes
    Object
  36. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  37. def isEven(n: Double): Boolean

    Permalink

    Returns true if the number given is even.

    Returns true if the number given is even.

    n

    The number to check.

    returns

    True if the given number is even. False if the given number is odd.

  38. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  39. def isOdd(n: Double): Boolean

    Permalink

    Returns true if the number given is odd.

    Returns true if the number given is odd.

    n

    The number to check.

    returns

    True if the given number is odd. False if the given number is even.

  40. def isPrototypeOf(v: Object): Boolean

    Permalink
    Definition Classes
    Object
  41. def linear(p0: Double, p1: Double, t: Double): Double

    Permalink

    Calculates a linear (interpolation) value over t.

    Calculates a linear (interpolation) value over t.

    p0

    number

    p1

    number

    t

    A value between 0 and 1.

    returns

    number

  42. def linearInterpolation(v: Double, k: Double): Double

    Permalink

    A Linear Interpolation Method, mostly used by Phaser.Tween.

    A Linear Interpolation Method, mostly used by Phaser.Tween.

    v

    The input array of values to interpolate between.

    k

    The percentage of interpolation, between 0 and 1.

    returns

    The interpolated value

  43. def mapLinear(x: Double, a1: Double, a2: Double, b1: Double, b2: Double): Double

    Permalink

    Linear mapping from range to range

    Linear mapping from range to range

    x

    The value to map

    a1

    First endpoint of the range

    a2

    Final endpoint of the range

    b1

    First endpoint of the range

    b2

    Final endpoint of the range

    returns

    number

  44. def max(): Double

    Permalink

    Variation of Math.max that can be passed either an array of numbers or the numbers as parameters.

    Variation of Math.max that can be passed either an array of numbers or the numbers as parameters. Prefer the standard Math.max function when appropriate.

    returns

    The largest value from those given.

  45. def maxAdd(value: Double, amount: Double, max: Double): Double

    Permalink

    Adds the given amount to the value, but never lets the value go over the specified maximum.

    Adds the given amount to the value, but never lets the value go over the specified maximum.

    value

    The value to add the amount to.

    amount

    The amount to add to the value.

    max

    The maximum the value is allowed to be.

    returns

    The new value.

  46. def maxProperty(): Double

    Permalink

    Variation of Math.max that can be passed a property and either an array of objects or the objects as parameters.

    Variation of Math.max that can be passed a property and either an array of objects or the objects as parameters. It will find the largest matching property value from the given objects.

    returns

    The largest value from those given.

  47. def min(): Double

    Permalink

    Variation of Math.min that can be passed either an array of numbers or the numbers as parameters.

    Variation of Math.min that can be passed either an array of numbers or the numbers as parameters. Prefer the standard Math.min function when appropriate.

    returns

    The lowest value from those given.

  48. def minProperty(): Double

    Permalink

    Variation of Math.min that can be passed a property and either an array of objects or the objects as parameters.

    Variation of Math.min that can be passed a property and either an array of objects or the objects as parameters. It will find the lowest matching property value from the given objects.

    returns

    The lowest value from those given.

  49. def minSub(value: Double, amount: Double, min: Double): Double

    Permalink

    Subtracts the given amount from the value, but never lets the value go below the specified minimum.

    Subtracts the given amount from the value, but never lets the value go below the specified minimum.

    value

    The base value.

    amount

    The amount to subtract from the base value.

    min

    The minimum the value is allowed to be.

    returns

    The new value.

  50. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  51. def normalizeAngle(angleRad: Double): Double

    Permalink

    Normalizes an angle to the [0,2pi) range.

    Normalizes an angle to the [0,2pi) range.

    angleRad

    The angle to normalize, in radians.

    returns

    The angle, fit within the [0,2pi] range, in radians.

  52. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  53. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  54. def percent(a: Double, b: Double, base: Double = js.native): Double

    Permalink

    Work out what percentage value a is of value b using the given base.

    Work out what percentage value a is of value b using the given base.

    a

    The value to work out the percentage for.

    b

    The value you wish to get the percentage of.

    base

    The base value.

    returns

    The percentage a is of b, between 0 and 1.

  55. def propertyIsEnumerable(v: String): Boolean

    Permalink
    Definition Classes
    Object
  56. def radToDeg(radians: Double): Double

    Permalink

    Convert radians to degrees.

    Convert radians to degrees.

    radians

    Angle in radians.

    returns

    Angle in degrees

  57. def reverseAngle(angleRad: Double): Double

    Permalink

    Reverses an angle.

    Reverses an angle.

    angleRad

    The angle to reverse, in radians.

    returns

    The reverse angle, in radians.

  58. def rotateToAngle(currentAngle: Double, targetAngle: Double, lerp: Double): Double

    Permalink

    Rotates currentAngle towards targetAngle, taking the shortest rotation distance.

    Rotates currentAngle towards targetAngle, taking the shortest rotation distance. The lerp argument is the amount to rotate by in this call.

    currentAngle

    The current angle, in radians.

    targetAngle

    The target angle to rotate to, in radians.

    lerp

    The lerp value to add to the current angle.

    returns

    The adjusted angle.

  59. def roundAwayFromZero(value: Double): Long

    Permalink

    Round to the next whole number away from zero.

    Round to the next whole number away from zero.

    value

    Any number.

    returns

    The rounded value of that number.

  60. def roundTo(value: Double, place: Double, base: Double): Double

    Permalink

    Round to some place comparative to a base, default is 10 for decimal place.

    Round to some place comparative to a base, default is 10 for decimal place. The place is represented by the power applied to base to get that place.

    value

    The value to round.

    place

    The place to round to.

    base

    The base to round in. Default is 10 for decimal.

    returns

    The rounded value.

  61. def shear(n: Double): Double

    Permalink

    Shear

    Shear

    n

    a number

    returns

    n mod 1

  62. def sign(x: Double): Double

    Permalink

    A value representing the sign of the value: -1 for negative, +1 for positive, 0 if value is 0.

    A value representing the sign of the value: -1 for negative, +1 for positive, 0 if value is 0. This works differently from Math.sign for values of NaN and -0, etc.

    x

    a number

    returns

    An integer in {-1, 0, 1}

  63. def sinCosGenerator(length: Double, sinAmplitude: Double, cosAmplitude: Double, frequency: Double): Any

    Permalink

    Generate a sine and cosine table simultaneously and extremely quickly.

    Generate a sine and cosine table simultaneously and extremely quickly. The parameters allow you to specify the length, amplitude and frequency of the wave. This generator is fast enough to be used in real-time. Code based on research by Franky of scene.at

    length

    The length of the wave

    sinAmplitude

    The amplitude to apply to the sine table (default 1.0) if you need values between say -/+ 125 then give 125 as the value

    cosAmplitude

    The amplitude to apply to the cosine table (default 1.0) if you need values between say -/+ 125 then give 125 as the value

    frequency

    The frequency of the sine and cosine table data

    returns

    Returns the table data.

  64. def smootherstep(x: Double, min: Double, max: Double): Double

    Permalink

    Smootherstep function as detailed at http://en.wikipedia.org/wiki/Smoothstep

    Smootherstep function as detailed at http://en.wikipedia.org/wiki/Smoothstep

    x

    The input value.

    min

    The left edge. Should be smaller than the right edge.

    max

    The right edge.

    returns

    A value between 0 and 1.

  65. def smoothstep(x: Double, min: Double, max: Double): Double

    Permalink

    Smoothstep function as detailed at http://en.wikipedia.org/wiki/Smoothstep

    Smoothstep function as detailed at http://en.wikipedia.org/wiki/Smoothstep

    x

    The input value.

    min

    The left edge. Should be smaller than the right edge.

    max

    The right edge.

    returns

    A value between 0 and 1.

  66. def snapTo(input: Double, gap: Double, start: Double = js.native): Double

    Permalink

    Snap a value to nearest grid slice, using rounding.

    Snap a value to nearest grid slice, using rounding. Example: if you have an interval gap of 5 and a position of 12... you will snap to 10 whereas 14 will snap to 15.

    input

    The value to snap.

    gap

    The interval gap of the grid.

    start

    Optional starting offset for gap.

    returns

    The snapped value.

  67. def snapToCeil(input: Double, gap: Double, start: Double = js.native): Double

    Permalink

    Snap a value to nearest grid slice, using ceil.

    Snap a value to nearest grid slice, using ceil. Example: if you have an interval gap of 5 and a position of 12... you will snap to 15. As will 14 will snap to 15... but 16 will snap to 20.

    input

    The value to snap.

    gap

    The interval gap of the grid.

    start

    Optional starting offset for gap.

    returns

    The snapped value.

  68. def snapToFloor(input: Double, gap: Double, start: Double = js.native): Double

    Permalink

    Snap a value to nearest grid slice, using floor.

    Snap a value to nearest grid slice, using floor. Example: if you have an interval gap of 5 and a position of 12... you will snap to 10. As will 14 snap to 10... but 16 will snap to 15.

    input

    The value to snap.

    gap

    The interval gap of the grid.

    start

    Optional starting offset for gap.

    returns

    The snapped value.

  69. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  70. def toLocaleString(): String

    Permalink
    Definition Classes
    Object
  71. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  72. def valueOf(): Any

    Permalink
    Definition Classes
    Object
  73. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  74. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  75. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  76. def within(a: Double, b: Double, tolerance: Double): Double

    Permalink

    Checks if two values are within the given tolerance of each other.

    Checks if two values are within the given tolerance of each other.

    a

    The first number to check

    b

    The second number to check

    tolerance

    The tolerance. Anything equal to or less than this is considered within the range.

    returns

    True if a is <= tolerance of b.

  77. def wrap(value: Double, min: Double, max: Double): Double

    Permalink

    Ensures that the value always stays between min and max, by wrapping the value around.

    Ensures that the value always stays between min and max, by wrapping the value around. If max is not larger than min the result is 0.

    value

    The value to wrap.

    min

    The minimum the value is allowed to be.

    max

    The maximum the value is allowed to be, should be larger than min.

    returns

    The wrapped value.

  78. def wrapAngle(angle: Double, radians: Double = js.native): Double

    Permalink

    Keeps an angle value between -180 and +180; or -PI and PI if radians.

    Keeps an angle value between -180 and +180; or -PI and PI if radians.

    angle

    The angle value to wrap

    radians

    Set to true if the angle is given in radians, otherwise degrees is expected.

  79. def wrapValue(value: Double, amount: Double, max: Double): Double

    Permalink

    Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around.

    Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around. Values must be positive integers, and are passed through Math.abs. See Phaser.Math#wrap for an alternative.

    value

    The value to add the amount to.

    amount

    The amount to add to the value.

    max

    The maximum the value is allowed to be.

    returns

    The wrapped value.

Inherited from Object

Inherited from Any

Inherited from AnyRef

Inherited from Any

Ungrouped