# How to zoom on to center of the screen

**URL:** <https://discourse.processing.org/t/how-to-zoom-on-to-center-of-the-screen/14090>\
**Category:** Coding Questions\
**Created:** [September 21, 2019, 12:46am UTC](https://discourse.processing.org/t/how-to-zoom-on-to-center-of-the-screen/14090 "2019-09-21T00:46:05Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 24, 2019, 2:11am UTC](https://discourse.processing.org/t/how-to-zoom-on-to-center-of-the-screen/14090/6 "2019-09-24T02:11:03Z")

</div>

> [@TheZipCreator](#):
>
> currently it zooms on the topleft corner of the screen. I want it to zoom on the center.

Your problem is almost certainly the order of operations. You must 1) translate before 2) zooming.

For a detailed discussion of why, see:

> [@How can I center an object on my screen that moves?](https://discourse.processing.org/t/how-can-i-center-an-object-on-my-screen-that-moves/12196/4):
>
> Understanding the relationship between translate, scale, and the idea of a 2D “camera” can sometimes be a bit tricky. It is worth reviewing the coordinate system and 2D transformations tutorials: [https://processing.org/tutorials/drawing/](https://processing.org/tutorials/drawing/)[https://processing.org/tutorials/transform2d/](https://processing.org/tutorials/transform2d/) However, in the end, there are three key transformations: translate to the center of the screen optionally scale the view, e.g. based on player speed or inter-player distance translate again to recenter the came…

> “These operations are order dependent if you are scaling: you must center your coordinate system first, then scale from the center, then translate to your view. If you try to scale first or last then bad things happen: either scaling happens from the top left, or the view scale does not match the drawing scale and they are misaligned.”

Problems with view and frame of reference are really difficult to debug about by just posting snippets, because so many different things in the code could impact the state of the matrix stack. If you still have trouble, post a complete mini sketch – an MCVE – to get feedback.

---

_[View the full topic](https://discourse.processing.org/t/how-to-zoom-on-to-center-of-the-screen/14090)._
