How to check x,y of object?

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

1 Like

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()

  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

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

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…

Use a PVector. https://processing.org/reference/PVector.html

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.

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);
  }
}