# How to check x,y of object?

**URL:** <https://discourse.processing.org/t/how-to-check-x-y-of-object/9345>\
**Category:** Coding Questions\
**Created:** [March 16, 2019, 12:32pm UTC](https://discourse.processing.org/t/how-to-check-x-y-of-object/9345 "2019-03-16T12:32:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shadowoftime](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@Shadowoftime](https://discourse.processing.org/u/Shadowoftime)\
**Post date:** [March 16, 2019, 12:32pm UTC](https://discourse.processing.org/t/how-to-check-x-y-of-object/9345/1 "2019-03-16T12:32:02Z")

</div>

Hello, I’m working on a game in processing and for the game I need to know each time the X and Y of a certain object, the same object constantly changing location and therefore I need you to tell me through which he will automatically check each time anew what x, y of the object.  
Thanks

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [March 16, 2019, 2:01pm UTC](https://discourse.processing.org/t/how-to-check-x-y-of-object/9345/2 "2019-03-16T14:01:44Z")

</div>

if you have a structure

> push / translate / rotate / scale / draw\_object() / pop

there is a way to know exactly where it is,  
if you save that info with:

> push / translate / rotate / scale / draw\_object()

```auto
  float jx = modelX(0, 0, 0);
  float jy = modelY(0, 0, 0);
  float jz = modelZ(0, 0, 0);

```

> pop

now can use that jx,jy,jz  
like for a collision…

old 3D test code here: [Trying to use modelX() but built a spiral galaxy of points - #4 by kll](https://discourse.processing.org/t/trying-to-use-modelx-but-built-a-spiral-galaxy-of-points/6064/4)

---

<div class="post-metadata">

**Author:** ![Shadowoftime](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@Shadowoftime](https://discourse.processing.org/u/Shadowoftime)\
**Post date:** [March 16, 2019, 3:20pm UTC](https://discourse.processing.org/t/how-to-check-x-y-of-object/9345/3 "2019-03-16T15:20:35Z")

</div>

im using pictures, the object im tallking about is a picture

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [March 16, 2019, 3:28pm UTC](https://discourse.processing.org/t/how-to-check-x-y-of-object/9345/4 "2019-03-16T15:28:55Z")

</div>

i not see how that matters, as you show a picture by  
image(img, a, b, c, d)  
so you know a,b ( x,y ) where you draw the picture,  
unless ( again see my first post )  
you do translate / rotate / scale … first only model can help you.

BUT  
if you talk about something what is inside the picture, a whole different story…

---

<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:** [March 17, 2019, 11:29pm UTC](https://discourse.processing.org/t/how-to-check-x-y-of-object/9345/5 "2019-03-17T23:29:53Z")

</div>

> [@Shadowoftime](#):
>
> I need to know each time the X and Y of a certain object

Use a PVector. [https://processing.org/reference/PVector.html](https://processing.org/reference/PVector.html)

```auto
PVector pv = new PVector();
void draw(){
  background(128);
  // constantly changing location
  pv.set(random(100), random(100));
  // check each time anew what x, y of the object
  ellipse(pv.x, pv.y, 10, 10);
  println(pv.x, pv.y);
}

```

If you need to make an object, add an x,y (or a PVector!) to the object.

```auto
Blob b = new Blob(0,0);

void draw(){
  background(128);
  // constantly changing location
  b.x = random(100);
  b.y = random(100);
  // check each time anew what x, y of the object
  b.render();
  println(b.x, b.y);
}

class Blob {
  float x;
  float y;
  Blob(float x, float y){
    this.x = x;
    this.y = y;
  }
  void render(){
    ellipse(x, y, 30, 10);
  }
}

```
