Skip to content

Methods not doing anything #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Fuzzyma opened this issue Aug 21, 2024 · 1 comment
Open

Methods not doing anything #495

Fuzzyma opened this issue Aug 21, 2024 · 1 comment

Comments

@Fuzzyma
Copy link

Fuzzyma commented Aug 21, 2024

I have an object at a certain position. Its center is say -200, -300.
I want to center this object in the viewport.

Whatever I do, it doesnt do anything. moveCenter doesnt change the viewport (doesnt matter which values I put), ensureVisible is the same. The only thing that did something was changing the pivot of the viewport but that feels wrong.

I cant figure out why all I try just does nothing so please take a look at the code and tell me whats wrong here:

const initViewport = (app, box) => {
  const viewport = new Viewport({
    screenWidth: app.canvas.width,
    screenHeight: app.canvas.height,
    // worldWidth: box.width,
    // worldHeight: box.height,
    worldWidth: app.canvas.width,
    worldHeight: app.canvas.height,
    events: app.renderer.events,
  });

  app.stage.addChild(viewport);

  // this would at least put the center of the bounding box to 0,0 but that doesnt help
  // viewport.pivot = { x: box.cx, y: box.cy }

  viewport
    .drag()
    .pinch()
    .wheel({ percent: 0.3 })
    .clamp({ direction: 'all' })
    .clampZoom({ minScale: 0.1, maxScale: 10 });

  // doesnt matter what I put here. It does nothing
  viewport.moveCenter(box.cy, box.cy);
  return viewport
}

Box is a bounding box with x, y, width, height, cx and cy.
I also tried changing the workd to the bounding box dimensions and also trie leaving it out (what does that even do?) but besides different initial rendering, moveCenter just doesnt do anything

@Fuzzyma
Copy link
Author

Fuzzyma commented Aug 21, 2024

So the reason why nothing was moving was because .clamp() restricted it from doing so.
Removing the line "fixed" it. However, now I dont have clamping anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant