Skip to content

Instantly share code, notes, and snippets.

@NoxWings
Last active March 10, 2020 15:15
Show Gist options
  • Save NoxWings/0f1644089016085aa3d071162f7ec99c to your computer and use it in GitHub Desktop.
Save NoxWings/0f1644089016085aa3d071162f7ec99c to your computer and use it in GitHub Desktop.
highlights PIXI interactive areas
function showInteractiveAreas () {
const root = APP.safeGetChildByName("");
const debugHitArea = "DebugHitArea";
const queue = [root];
while (queue.length > 0) {
const element = queue.pop();
if (element.name === debugHitArea)
element.parent.removeChild(element);
queue.push(...(element.children || []));
if (!element.interactive) continue;
const g = new PIXI.Graphics();
g.alpha = 0.5;
g.name = debugHitArea;
element.addChild(g);
if (element.hitArea) {
g.lineStyle(2, 0xFFBD01, 1);
g.beginFill(0xC34288);
const { x, y, width, height } = element.hitArea;
g.drawRect(x, y, width, height);
} else {
g.lineStyle(2, 0xFFBD01, 1);
g.beginFill(0x888888);
const { x, y } = element.anchor ? element.anchor : { x: 0, y: 0 };
const { width, height } = element;
g.drawRect(-width * x, -height * y, width, height);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment