# P5js V2 get current camera?

**URL:** <https://discourse.processing.org/t/p5js-v2-get-current-camera/47172>\
**Category:** p5.js\
**Created:** [September 18, 2025, 2:20pm UTC](https://discourse.processing.org/t/p5js-v2-get-current-camera/47172 "2025-09-18T14:20:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 18, 2025, 2:20pm UTC](https://discourse.processing.org/t/p5js-v2-get-current-camera/47172/1 "2025-09-18T14:20:53Z")

</div>

In V1 I could get a reference to the current camera like this -

```auto
        let p5canvas;

        function setup() {
            p5canvas = createCanvas(400, 400, WEBGL);
            console.log(p5canvas._curCamera);
        }

        function draw() {
            background(220);
        }

```

but in V2 of `p5.Canvas` the variable `_curCamera` is undefined.

It is not ideal solution because the variable `_curCamera` should be treated as a private variable but needs must.

So what I am looking for is a statement that will give me a reference to the current camera that is the same in V1 and V2.

Any help appreciated 😁

---

<div class="post-metadata">

**Author:** ![davepagurek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/davepagurek/32/17535_2.png) [@davepagurek](https://discourse.processing.org/u/davepagurek)\
**Post date:** [September 18, 2025, 3:04pm UTC](https://discourse.processing.org/t/p5js-v2-get-current-camera/47172/2 "2025-09-18T15:04:44Z")

</div>

There’s not a public API for either, but in v2 `p5Canvas.states.curCamera` is the equivalent of what you’re doing. So you could do something like this if you wanted to make yourself a function that works in both:

```js
function getCamera(renderer) {
  if (VERSION.startsWith('2.')) {
    return renderer.states.curCamera;
  } else {
    return renderer._curCamera;
  }
}
// Usage: const cam = getCamera(p5canvas)

```

(This would probably be a useful API to exist; if you’re interested, feel free to open a feature request on github!)

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 18, 2025, 8:47pm UTC](https://discourse.processing.org/t/p5js-v2-get-current-camera/47172/3 "2025-09-18T20:47:31Z")

</div>

I noticed that my canvasGUI library examples using WEBGL worked with p5js V1 but failed with V2 . I narrowed the problem down to accessing the current camera hence my question.

So @davepagurek thanks for your reply I have successfully incorporated the idea into canvasGUI. 👍

I created a class attribute to get the major version number -

```auto
    // Remember major version number of p5js for camera selection
    this._p5MajorVersion = Number(p.VERSION.split('.')[0]);

```

I did this to avoid the string comparison since I have to access the camera every frame.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 19, 2025, 11:26am UTC](https://discourse.processing.org/t/p5js-v2-get-current-camera/47172/4 "2025-09-19T11:26:44Z")

</div>

> [@davepagurek](#):
>
> (This would probably be a useful API to exist; if you’re interested, feel free to open a feature request on github!)

[Issue](https://github.com/processing/p5.js/issues/8097) has been raised on github
