guanw / sr

0 stars 0 forks source link

make bound of entity visible with debugtool on #21

Closed guanw closed 1 month ago

guanw commented 1 month ago

import * as PIXI from "pixi.js";

// Function to create and add a bounding box around a sprite function drawBoundingBox(sprite: PIXI.Sprite, container: PIXI.Container) { const bounds = sprite.getBounds();

// Create a graphics object
const graphics = new PIXI.Graphics();

// Set the line style: thickness and color
graphics.lineStyle(2, 0xff0000); // Red color for the bounding box

// Draw a rectangle around the bounds
graphics.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);

// Add the graphics object to the same container as the sprite
container.addChild(graphics);

}

// Example usage:

// Assuming avatar is your avatar sprite and obstacle is an obstacle sprite const avatarContainer = new PIXI.Container(); // Container for avatar and its bounding box const obstacleContainer = new PIXI.Container(); // Container for obstacles and their bounding boxes

// Draw bounding boxes around the avatar and obstacle drawBoundingBox(avatar, avatarContainer); drawBoundingBox(obstacle, obstacleContainer);

// Add containers to the main layer or scene app.stage.addChild(avatarContainer); app.stage.addChild(obstacleContainer);

image
guanw commented 1 month ago

df5ce2933fe4560204e9155c769b8ba1288d93d4