skeleton:createAttachment()

Overview

Creates a new region attachment that shows a region of the skeleton’s own atlas (the atlas its skeleton data was loaded with). Put it in a custom skin with skin:setAttachment() or show it directly with slot.attachment. No animation of the skeleton data drives it: it is not one of the data’s attachments.

Syntax

local attachment = skeleton:createAttachment({ region = regionName, name = attachmentName })

Parameters

  • region (required):

    string – The name of a region in the skeleton’s atlas. A name the atlas does not have raises Region not found in the skeleton's atlas: <name>.

  • name (required):

    string – The attachment’s name.

  • width, height (optional):

    number – The attachment’s size. Defaults to the region’s original size (originalWidth, originalHeight of attachment.region).

  • x, y, rotation, scaleX, scaleY (optional):

    number – The attachment’s offset from its bone, rotation in degrees and scale. Defaults to 0, 0, 0, 1, 1.

A missing or empty name and a non-number geometry field raise.

Return value

Attachment – A new region attachment (type == "region") of the skeleton’s skeleton data.

Example

local badge = skeleton:createAttachment({ region = "crosshair", name = "badge", scaleX = 0.5, scaleY = 0.5 })

local skin = skeleton:createSkin("badged")
skin:addSkin("default"):setAttachment("gun", "gun", badge)
skeleton:setSkin(skin)