// 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);
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();
}
// Example usage:
// Assuming
avatar
is your avatar sprite andobstacle
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);