pixi-viewport
pixi-viewport copied to clipboard
How do I center on an arbitrary object?
Sorry for the stupid question, but I got lost and confused.
I have created a small example, what I wanted to achieve there is simply to be able to move the white dot to the center of the canvas, for instance after the zooming/dragging
https://codesandbox.io/s/pixi-viewport-test-bqbm8
Thank you very much!
Simpler than you think. First you need to set the canvas to the right size:
Object.assign(app.view.style,
{
width: width + 'px',
height: height + 'px',
overflow: 'hidden'
})
Then you just need to viewport.moveCenter({ x: 25, y: 25 }), where (25, 25) is the center of your object.
Thank you so much, it worked! So this method is always in 'world' coordinates?
Yes. Most functions are in world coordinates. Easier to work with the viewport.