Quantcast
Channel: Pixi.js Latest Topics
Viewing all articles
Browse latest Browse all 3981

getBounds() returns a rectangle significantly larger than the sprite

$
0
0

I am getting strange behaviour from getBounds, especially when my sprite is rotated. Consider the following code, which loads up a tank pic (attached).

// Convenient PIXI aliases
const Graphics = PIXI.Graphics
const ParticleContainer = PIXI.ParticleContainer
const Container = PIXI.Container
const Sprite = PIXI.Sprite



// Set up PIXI view
let app = new PIXI.Application(
    {
      width: 600,
      height: 600,
      background: 0x000000,
      antialias: true,
      transparent: false,
      resolution: 1,
//    resizeTo: window
    })
app.renderer.view.style.position = "absolute";
app.renderer.view.style.display = "block";
app.renderer.autoDensity = true;
document.body.appendChild(app.view)


// Add player 1
let player1 = new Container()
let player1Tank = Sprite.from("tank body.png")
player1.addChild(player1Tank)
player1.angle = 30

player1.position.x = 150
player1.position.y = 150

app.stage.addChild(player1)

// call player1.getBounds() in the console in Chrome Dev Tools. You will get a rectangle which is bigger by about 8 pixels
// or so on all sides than the actual (rotated) tank.

If you call  player1.getBounds() in the console in Chrome Dev Tools, you get a rectangle which is bigger by about 8 pixels than it needs to be (that "bloat" of pixels varies depending on the rotation of the tank.)

tank body.png


Viewing all articles
Browse latest Browse all 3981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>