pixi-viewport icon indicating copy to clipboard operation
pixi-viewport copied to clipboard

How do I center on an arbitrary object?

Open w8r opened this issue 5 years ago • 3 comments

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!

w8r avatar Mar 01 '20 18:03 w8r

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.

davidfig avatar Mar 02 '20 00:03 davidfig

Thank you so much, it worked! So this method is always in 'world' coordinates?

w8r avatar Mar 03 '20 14:03 w8r

Yes. Most functions are in world coordinates. Easier to work with the viewport.

davidfig avatar Mar 04 '20 00:03 davidfig