Small World Engine API Reference - v0.46.1
    Preparing search index...

    Class Vector2D

    A class representing a 2D vector. Data is stored as individual properties for fast access in JS engines.

    Implements

    Index

    Constructors

    • Creates a new Vector2D.

      Parameters

      • x: number = 0

        The x component. Defaults to 0.

      • y: number = 0

        The y component. Defaults to 0.

      Returns Vector2D

    Properties

    x: number = 0

    The x component. Defaults to 0.

    y: number = 0

    The y component. Defaults to 0.

    Methods

    • Adds a scalar to this vector.

      Parameters

      • s: number

        The scalar to add.

      Returns this

      this

    • Calculates the Euclidean distance to another vector.

      Parameters

      Returns number

      The distance.

    • Calculates the squared distance to another vector.

      Parameters

      Returns number

      The squared distance.

    • Divides this vector by a scalar.

      Parameters

      • s: number

        The scalar to divide by.

      Returns this

      this

    • Calculates the dot product of this vector and another.

      Parameters

      Returns number

      The dot product.

    • Scales the vector by a scalar value.

      Parameters

      • s: number

        The scalar factor.

      Returns this

      this

    • Sets the components of the vector.

      Parameters

      • x: number

        The x component.

      • y: number

        The y component.

      Returns this

      this