skeleton_attachment_create_colour

When you create you skeletal animation sprite, you can assign attachment slots and attachments to go in them. These are simply images (sprites) that are separate from the animation but when attached will move along with the bone they are attached to. Normally you would assign these attachments in your animation program (Spine), but with this function you can create your own at run-time using a sprite asset from your game. the function requires that you give the attachment a name (as a string) and then set the sprite_index and image_index to use, as well as the x and y origin (which can be different to that defined by the sprite in the sprite properties), and you can also set any transforms that you wish to be applied to the image when attached, as well as the colour to be blended with the image and it's alpha (transparency) value. If the attachment was successfully created the function will return 1 and if it was not (you supplied an invalid sprite index, or the base sprite is not a Spine sprite) then it will return -1.

It is worth noting that the instance sprite can have a blend colour and alpha setting (image_blend and image_alpha), as can the attachment slot (see the function skeleton_slot_colour_set()), and so the final colour and alpha that the assigned attachment sprite for the slot will have will be a composite of all these values.

NOTE In case there is a possibility that an attachment with the given name already exists you can check this using skeleton_attachment_exists, as trying to create an attachment with an existing name will throw an error.

Syntax:

skeleton_attachment_create_colour(name, sprite, ind, xorigin, yorigin, xscale, yscale, rot, colour, alpha);

ArgumentTypeDescription
nameStringThe name (as a string) of the attachment to create.
spriteSprite AssetThe sprite_index to get the attachment image from.
indRealThe image_index to get the attachment image from.
xoriginRealThe x origin for the image being used.
yoriginRealThe y origin for the image being used.
xscaleRealThe horizontal scaling of the image, as a multiplier: 1 = normal scaling, 0.5 is half etc...
yscaleRealThe vertical scaling of the image, as a multiplier: 1 = normal scaling, 0.5 is half etc...
rotRealThe rotation of the image: 0 = normal, 90 = turned 90° counter-clockwise etc.
ColourColourThe colour value to use (A constant, integer or hex value).
AlphaRealThe alpha value to use (from 0 to 1).

 

Returns:

Real (1 if successful, -1 if not)

 

Example:

skeleton_attachment_create_colour("sword", spr_Weapons, 0, 0, 80, 1, 1, 90, c_red, 1);
skeleton_attachment_create_colour("knife", spr_Weapons, 1, 0, 45, 1, 1, 90, c_yellow, 1);
skeleton_attachment_create_colour("crossbow", spr_Weapons, 0, 10, 30, 1, 1, 0, c_white, 0.5);
skeleton_attachment_set("slot_leftHand", choose("sword", "knife", "crossbow"));

The above code would check the currently assigned attachment name for the slot named "slot_leftHand" and if an empty string is returned, a new sprite is attached.