The SpriteUtils class provides utility methods for working with Sprite objects in LayaAir.

SpriteUtils 类提供了用于处理 LayaAir 中的 Sprite 对象的实用方法。

构造函数

方法

  • 参数

    • dom: any

      The reference to the DOM element.

    • coordinateSpace: Sprite

      The coordinate space. It should not be a reference to Stage.

    • x: number

      The x coordinate relative to the coordinateSpace.

    • y: number

      The y coordinate relative to the coordinateSpace.

    • width: number

      The width of the area.

    • height: number

      The height of the area.

    返回 void

    Make a DOM element fit within a specific area of the stage.

    使DOM元素适应舞台内指定区域。

  • 参数

    • sprite: Sprite
    • 可选recursive: boolean

      Whether to get the bounding box of the child object recursively

    • 可选ignoreInvisibles: boolean

      Whether to ignore invisible objects

    • 可选ignoreScale: boolean

      Whether to ignore scaling

    • 可选out: Rectangle

      (Optional) Output object for calculation results

    返回 Rectangle

    Bounding box

    Get the bounding box of the child

    获取孩子的包围盒

  • 参数

    • sprite: Sprite

      The Sprite object to calculate.

    返回 {
        scaleX: number;
        scaleY: number;
        x: number;
        y: number;
    }

    The object with the calculated values.

    • scaleX: number
    • scaleY: number
    • x: number
    • y: number

    Calculates the global coordinates and scaling values of the specified Sprite display object, and returns a object containing the calculated X and Y coordinates as well as the scaleX and scaleY values.

    计算传入的显示对象 Sprite 在全局坐标系中的坐标和缩放值,返回一个对象,存放计算出的坐标 X 值、Y 值、ScaleX 值和 ScaleY 值。

  • 参数

    • sprite: Sprite

      The display object Sprite.

    • x0: number

      The X-axis coordinate of the first point.

    • y0: number

      The Y-axis coordinate of the first point.

    • x1: number

      The X-axis coordinate of the second point.

    • y1: number

      The Y-axis coordinate of the second point.

    • 可选out: Rectangle

      The rectangle object to be returned. If not provided, a new rectangle object will be created.

    返回 Rectangle

    The rectangle object Rectangle composed of the two points on the stage coordinate system.

    Returns the smallest rectangular area object composed of two points on the stage coordinate system for the given display object Sprite.

    根据传入的显示对象 Sprite 和此显示对象上的两个点,返回这两点在舞台坐标系上组成的最小矩形区域对象。

  • 参数

    • sprite: Sprite

      The Sprite object for which to retrieve the bounding rectangle.

    • 可选sizeOnly: boolean

      If true, only the size of the sprite is considered, ignoring the graphics and children. Default is true.

    • 可选out: Rectangle

      An optional Rectangle object to store the result. If not provided, a new Rectangle object will be created.

    返回 Rectangle

    A Rectangle object representing the bounding rectangle of the sprite.

    Retrieves the rectangle that bounds the sprite, based on the sprite's own coordinate space.

    获取包含精灵的边界矩形,基于精灵自身的坐标空间。

  • 参数

    • coordinateSpace: Sprite

      The coordinate space, must not be a Stage reference.

    • x: number

      The x coordinate relative to the coordinateSpace.

    • y: number

      The y coordinate relative to the coordinateSpace.

    返回 {
        scaleX: number;
        scaleY: number;
        x: number;
        y: number;
    }

    An object containing the transformed x, y coordinates, and scale factor.

    • scaleX: number
    • scaleY: number
    • x: number
    • y: number

    Retrieves the transform of a specified area relative to the top-left corner of the window.

    获取指定区域内相对于窗口左上角的transform。

  • 参数

    • sp: Sprite

      The Sprite object whose global rectangle is to be converted.

    • rect: Rectangle

      The global rectangle to be converted.

    • 可选out: Rectangle

      An optional Rectangle object to store the result. If not provided, a new Rectangle object will be created.

    返回 Rectangle

    The converted rectangle in local coordinates.

    Converts a rectangle from global coordinates to local coordinates.

    将矩形从全局坐标转换为本地坐标。

  • 参数

    • sp: Sprite

      The Sprite object whose local rectangle is to be converted.

    • rect: Rectangle

      The local rectangle to be converted.

    • 可选out: Rectangle

      An optional Rectangle object to store the result. If not provided, a new Rectangle object will be created.

    返回 Rectangle

    The converted rectangle in global coordinates.

    Converts a rectangle from local coordinates to global coordinates.

    将矩形从本地坐标转换为全局坐标。

  • 参数

    • sprite: Sprite

      The Sprite object to set the position and size for.

    • rect: Readonly<Rectangle>

      The rectangle object containing the position and size to set.

    返回 void

    Sets the position and size of a Sprite based on a given rectangle.

    根据给定的矩形设置 Sprite 的位置和大小。

  • 参数

    • sp: Sprite

      The Sprite object whose local rectangle is to be transformed.

    • rect: Rectangle

      The local rectangle to be transformed.

    • 可选targetSpace: Sprite

      The target Sprite object representing the coordinate space to which the rectangle should be transformed. If not provided, the transformation will be done in the global coordinate space.

    • 可选out: Rectangle

      An optional Rectangle object to store the result. If not provided, a new Rectangle object will be created.

    返回 Rectangle

    The transformed rectangle in the target coordinate space.

    Transforms a rectangle from the local coordinate space of a Sprite to another target coordinate space.

    将矩形从 Sprite 的本地坐标空间转换为另一个目标坐标空间。