Skip to content

Instantly share code, notes, and snippets.

@katsaii
Last active September 14, 2019 00:17
Show Gist options
  • Save katsaii/718abc99f8cfe3ef1524890d7d2bc6f0 to your computer and use it in GitHub Desktop.
Save katsaii/718abc99f8cfe3ef1524890d7d2bc6f0 to your computer and use it in GitHub Desktop.
Draws a sprites corrected bounding box.
/// @desc Draws the bounding box outline for this sprite. Only supports axis-aligned and oriented bounding boxes.
/// @param sprite {Real} The sprite to draw.
/// @param subimg {Real} The subimage of the sprite to use.
/// @param x {Real} X position.
/// @param y {Real} Y position.
/// @param xscale {Real} X scale.
/// @param yscale {Real} Y scale.
/// @param rot {Real} Rotation.
/// @param outline {Boolean} Whether to draw an outline or use a solid fill.
/// @author Kat @katsaii
if (argument1 < 0 || argument1 >= sprite_get_number(argument0)) then return;
var ox = sprite_get_xoffset(argument0);
var oy = sprite_get_yoffset(argument0);
var left = sprite_get_bbox_left(argument0) - 1 - ox;
var top = sprite_get_bbox_top(argument0) - 1 - oy;
var right = sprite_get_bbox_right(argument0) - ox;
var bottom = sprite_get_bbox_bottom(argument0) - oy;
var world = matrix_get(matrix_world);
var trans = matrix_multiply(
matrix_build(0, 0, 0, 0, 0, 0, argument4, argument5, 1),
matrix_build(argument2, argument3, 0, 0, 0, argument6, 1, 1, 1));
matrix_set(matrix_world, trans);
draw_rectangle(left, top, right, bottom, argument7);
matrix_set(matrix_world, world);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment