Argument Description bone The name (as a string) of the bone. map The (previously created) ds_map that stores the bone data.
Your skeletal animation is made up of a number of "bones", which you will have defined and given names to in your animation program, and this function can be used to get certain data for the named bone at any time. Note that this data refers to the current pose for the skeleton, depending on the animation set used, and the function requires a previously created ds_map, which will then have the following keys and their equivalent values after calling the function:
- "x": The local x position of the bone relative to the parent bone.
- "y": The local y position of the bone relative to the parent bone.
- "angle": The local rotation of the bone relative to the parent bone.
- "xscale": The local horizontal scale of the bone, in reference to the parent bone.
- "yscale": The local vertical scale of the bone, in reference to the parent bone.
- "worldX": The x position of the bone relative to the root of the animation (this is a read only value).
- "worldY": The y position of the bone relative to the root of the animation (this is a read only value).
- "worldSignX": This indicates whether a bone has been scaled along the X axis and will return either 1 (positive scaling) or -1 (negative scaling). Note that this is a read only value.
- "worldSignY": This indicates whether a bone has been scaled along the Y axis and will return either 1 (positive scaling) or -1 (negative scaling). Note that this is a read only value.
- "appliedAngle": This is the local rotation used to pose the skeleton bones.
- "parent": The name (a string) of the parent bone.
The map data returned is similar to that returned for the default pose when you use skeleton_bone_data_get, only now you have the extra "world" keys. These refer to the position of the bone relative to the root (origin) of the skeletal animation sprite, and the returned values do not take into consideration any scaling or rotation that has been done by setting the built-in sprite variables like image_xscale or image_angle. The world values are read only and cannot be set.
This function is provided so that you can "intercept" animation data and modify it before it is drawn on the screen, and as such you would want to use it in the Other - Animation Update event, since this event is triggered just before the Draw Events.IMPORTANT! This function is not available with the Trial Licence of the product.
var map = ds_map_create();
var xx = ds_map_find_value(map, "worldX");
var yy = ds_map_find_value(map, "worldY");
var deltax = mouse_x - (x + xx);
var deltay = mouse_y - (y + yy);
var angle = -radtodeg(arctan2(deltay, deltax));
ds_map_replace(map, "angle", angle);
The above code creates a ds_map and then populates it with the data from the bone named "head". It then extracts the world position for the bone, and uses that data to set the "angle" of the bone to track the mouse position in the game.