# P5 canvas position on device orientation change

**URL:** https://discourse.processing.org/t/p5-canvas-position-on-device-orientation-change/23398
**Category:** Coding Questions
**Created:** [August 20, 2020, 6:09pm UTC](https://discourse.processing.org/t/p5-canvas-position-on-device-orientation-change/23398 "2020-08-20T18:09:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![odotdotdot](https://avatars.discourse-cdn.com/v4/letter/o/c0e974/32.png) [@odotdotdot](https://discourse.processing.org/u/odotdotdot)
#### Post date: [August 20, 2020, 6:09pm UTC](https://discourse.processing.org/t/p5-canvas-position-on-device-orientation-change/23398/1 "2020-08-20T18:09:48Z")

</div>

Hi,

I’m working on a browser game and I’ve just extended functionality to mobile browsers.

I’m having some trouble reigning in the canvas position after a device orientation change (i.e. flipping your phone from portrait to landscape)

I experimented with the deviceTurned method, but it did not seem to execute in chrome on an iphone.

I settled on the idea of adding an event listener for the flip and calling my windowResized function, but the effect is still less than desired (satisfactory in safari, chrome portrait not so much).

The game is live at [leverkuhn.app](http://leverkuhn.app) if you’d like to see what I’m talking about.

Any ideas on the best approach to this problem?

event listener:

```auto
      window.addEventListener("orientationchange", function(event){
        windowResized()
        });

```

css:

```auto
      body{
        padding: 0;
        margin: 0;
        background-color: rgb(53,53,53);
        display:flex;
        justify-content: center;
        align-items: center;
}

```

---

<div class="post-metadata">

### Author: ![hoowdie](https://avatars.discourse-cdn.com/v4/letter/h/71c47a/32.png) [@hoowdie](https://discourse.processing.org/u/hoowdie)
#### Post date: [May 16, 2021, 9:57am UTC](https://discourse.processing.org/t/p5-canvas-position-on-device-orientation-change/23398/2 "2021-05-16T09:57:35Z")

</div>

Hey odotdotdot,

amazing Game you have there!

I also have trouble with deviceOrientation changes, sometimes it triggers, sometimes not, everthing is very weird…

Have you found a solid solution for this problem yet?
