phaser - v4.0.0-rc.4
    Preparing search index...

    Provides methods used for getting and setting the position, scale and rotation of a Game Object.

    interface Transform {
        angle: number;
        hasTransformComponent: boolean;
        rotation: number;
        scale: number;
        scaleX: number;
        scaleY: number;
        w: number;
        x: number;
        y: number;
        z: number;
        copyPosition(source: Vector2Like | Vector3Like | Vector4Like): this;
        getLocalPoint(
            x: number,
            y: number,
            point?: Math.Vector2,
            camera?: Cameras.Scene2D.Camera,
        ): Math.Vector2;
        getLocalTransformMatrix(tempMatrix?: TransformMatrix): TransformMatrix;
        getParentRotation(): number;
        getWorldPoint(
            point?: Math.Vector2,
            tempMatrix?: TransformMatrix,
            parentMatrix?: TransformMatrix,
        ): Math.Vector2;
        getWorldTransformMatrix(
            tempMatrix?: TransformMatrix,
            parentMatrix?: TransformMatrix,
        ): TransformMatrix;
        setAngle(degrees?: number): this;
        setPosition(x?: number, y?: number, z?: number, w?: number): this;
        setRandomPosition(
            x?: number,
            y?: number,
            width?: number,
            height?: number,
        ): this;
        setRotation(radians?: number): this;
        setScale(x?: number, y?: number): this;
        setW(value?: number): this;
        setX(value?: number): this;
        setY(value?: number): this;
        setZ(value?: number): this;
    }

    Implemented by

    Index

    Properties

    angle: number

    The angle of this Game Object as expressed in degrees.

    Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left and -90 is up.

    If you prefer to work in radians, see the rotation property instead.

    hasTransformComponent: boolean

    A property indicating that a Game Object has this component.

    rotation: number

    The angle of this Game Object in radians.

    Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left and -PI/2 is up.

    If you prefer to work in degrees, see the angle property instead.

    scale: number

    This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object to the same value, at the same time. When reading this value the result returned is (scaleX + scaleY) / 2.

    Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this isn't the case, use the scaleX or scaleY properties instead.

    scaleX: number

    The horizontal scale of this Game Object.

    scaleY: number

    The vertical scale of this Game Object.

    w: number

    The w position of this Game Object.

    x: number

    The x position of this Game Object.

    y: number

    The y position of this Game Object.

    z: number

    The z position of this Game Object.

    Note: The z position does not control the rendering order of 2D Game Objects. Use Phaser.GameObjects.Components.Depth#depth instead.

    Methods

    • Takes the given x and y coordinates and converts them into local space for this Game Object, taking into account parent and local transforms, and the Display Origin.

      The returned Vector2 contains the translated point in its properties.

      A Camera needs to be provided in order to handle modified scroll factors. If no camera is specified, it will use the main camera from the Scene to which this Game Object belongs.

      Parameters

      • x: number

        The x position to translate.

      • y: number

        The y position to translate.

      • Optionalpoint: Math.Vector2

        A Vector2, or point-like object, to store the results in.

      • Optionalcamera: Cameras.Scene2D.Camera

        The Camera which is being tested against. If not given will use the Scene default camera.

      Returns Math.Vector2

    • Gets the sum total rotation of all of this Game Objects parent Containers.

      The returned value is in radians and will be zero if this Game Object has no parent container.

      Returns number

    • Sets the angle of this Game Object.

      Parameters

      • Optionaldegrees: number

        The rotation of this Game Object, in degrees. Default 0.

      Returns this

    • Sets the position of this Game Object.

      Parameters

      • Optionalx: number

        The x position of this Game Object. Default 0.

      • Optionaly: number

        The y position of this Game Object. If not set it will use the x value. Default x.

      • Optionalz: number

        The z position of this Game Object. Default 0.

      • Optionalw: number

        The w position of this Game Object. Default 0.

      Returns this

    • Sets the position of this Game Object to be a random position within the confines of the given area.

      If no area is specified a random position between 0 x 0 and the game width x height is used instead.

      The position does not factor in the size of this Game Object, meaning that only the origin is guaranteed to be within the area.

      Parameters

      • Optionalx: number

        The x position of the top-left of the random area. Default 0.

      • Optionaly: number

        The y position of the top-left of the random area. Default 0.

      • Optionalwidth: number

        The width of the random area.

      • Optionalheight: number

        The height of the random area.

      Returns this

    • Sets the rotation of this Game Object.

      Parameters

      • Optionalradians: number

        The rotation of this Game Object, in radians. Default 0.

      Returns this

    • Sets the scale of this Game Object.

      Parameters

      • Optionalx: number

        The horizontal scale of this Game Object. Default 1.

      • Optionaly: number

        The vertical scale of this Game Object. If not set it will use the x value. Default x.

      Returns this

    • Sets the w position of this Game Object.

      Parameters

      • Optionalvalue: number

        The w position of this Game Object. Default 0.

      Returns this

    • Sets the x position of this Game Object.

      Parameters

      • Optionalvalue: number

        The x position of this Game Object. Default 0.

      Returns this

    • Sets the y position of this Game Object.

      Parameters

      • Optionalvalue: number

        The y position of this Game Object. Default 0.

      Returns this