# Draw pictures by y positions

**URL:** https://discourse.processing.org/t/draw-pictures-by-y-positions/19916
**Category:** Coding Questions
**Created:** [April 19, 2020, 1:55am UTC](https://discourse.processing.org/t/draw-pictures-by-y-positions/19916 "2020-04-19T01:55:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [April 19, 2020, 1:55am UTC](https://discourse.processing.org/t/draw-pictures-by-y-positions/19916/1 "2020-04-19T01:55:14Z")

</div>

Hello. The situation needs help.

I (for the game) need the characters to be drawn gradually (as if the game understands which character is closer to the camera and which is not).  
And at the same time, that there were rendering layers.

While there were few objects, I managed the usual double for () in height (from top to bottom I checked each object to see if it matches the desired height, if so, I drew).

```auto
for(int i=int(-h/10); i<int(h+h/10); i+=h100){
    //hero
    if(int(posHero.y)>=i&&int(posHero.y)<i+h100){drawHero();}
    //enemy
    for(int ii=0; ii<100; ii++){
      if(typeEnemy[ii]!=0){
    if(int(posEnemy[ii].y)>=i&&int(posEnemy[ii].y)<i+h100){drawEnemy(ii);}//if enemy pos y == i
      }//if need draw enemy
    }//for draw enemy
  }//for

```

What happened - added a picture.  
But there are more objects, I need a new code.  
I know that sounds silly and hard to understand.  
But try, please.

 ![Screenshot_20200321-082420](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6a39e39d57fd7950665f6bac48270eb1729dc498.jpeg) ![Screenshot_20200322-052244~2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/916b92a415b6d5891bb397a66aa9c15296ebb9c0.png)

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 19, 2020, 9:25am UTC](https://discourse.processing.org/t/draw-pictures-by-y-positions/19916/2 "2020-04-19T09:25:12Z")

</div>

can you sort by y-value (or virtual z-value?) and then display in that order?

Chrisir

---

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [April 23, 2020, 5:18pm UTC](https://discourse.processing.org/t/draw-pictures-by-y-positions/19916/3 "2020-04-23T17:18:58Z")

</div>

Sorry, but how to sort?  
First, write to some sort of array the buffer [] of the object number?  
Tell me please.

---

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [April 25, 2020, 6:06am UTC](https://discourse.processing.org/t/draw-pictures-by-y-positions/19916/4 "2020-04-25T06:06:28Z")

</div>

I figured out how to use sort();  
But I don’t understand how to write it into the code.After all, now I have the rest of the variables that are not tied to the desired rendering number yPosEnemy.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 26, 2020, 2:25pm UTC](https://discourse.processing.org/t/draw-pictures-by-y-positions/19916/5 "2020-04-26T14:25:57Z")

</div>

> [@NoName](#):
>
> But I don’t understand how to write it into the code

When you have sorted the figures/ players/ enemies by y value, draw the enemy with the smallest y first, then the figure with the second highest and so forth so that they don‘t cover each other in a wrong way
