Can i made a layers with translate(x,y,layer) ? without resize ?

Here is example... i want to only use layer without resize :/

ArrayList<GameObject> objects = new ArrayList <GameObject>();

void setup() {
  size(500, 500, P3D);
  objects.add(new GameObject(150,300,25));
  objects.add(new GameObject(200,300,-2));
}

void draw() {
  background(45);
  objects.get(0).layer = width/2 - mouseX;
  for (int i = objects.size()-1; i >= 0; i--) {
    GameObject object = objects.get(i);
    pushMatrix();
    translate(object.x, object.y, object.layer);
    fill(object.c);
    noStroke();
    rect(0,0,100,100);
    popMatrix();
  }
}

class GameObject {
  int x, y, layer;
  color c = color(random(255),random(255),random(255));
  GameObject(int x, int y, int layer) {
    this.x = x;
    this.y = y;
    this.layer = layer;
  }
}
Tagged:

Answers

  • edited May 2018

    why do you start a new topic?

    Again, as I told you before: you need to explain in a longer way what you mean.

    • What do you want to achieve?

    • What happens now falsely, what do you want to happen instead?

    • Which line number is involved??

    To your problem

    e.g. you want to use layer without resize: there is no resize() in your code, so what do you mean?

    object.layer is the Z position in 3D (the depth)

    you can as well call it z

    processing is taking care in 3D space what is in front of what, so Z -25 is always behind +25

    in 2D space, what is in front and what is behind is made like the order in that you draw things. Like on a real canvas, when you draw a forest and then Robin Hood, Robin is in front the forest, the forest is in the background.

  • How to simply take write layer and the object was draw up or down of other layer objects ?

  • 2D or 3D?

  • as I said, it is hard for me to work with you because you don't explain much.

    Is English your first language? Don't write so brief.

    I can't help you.

  • Hi GeorgeJava,

    If you don't want an object's depth on the z-axis to change its size as perceived by the camera you can use orthographic ( https://processing.org/reference/ortho_.html ) rather than the default perspective ( https://processing.org/reference/perspective_.html ).

    void setup() {
      size(500, 500, P3D);
      ortho();
      objects.add(new GameObject(150,300,25));
      objects.add(new GameObject(200,300,-2));
    }
    
Sign In or Register to comment.