# Perspective Depth

**URL:** <https://forum.kirupa.com/t/perspective-depth/62525>\
**Category:** flash\
**Created:** [August 28, 2004, 7:54pm UTC](https://forum.kirupa.com/t/perspective-depth/62525 "2004-08-28T19:54:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ferdi](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ferdi/32/689_2.png) [@Ferdi](https://forum.kirupa.com/u/Ferdi)\
**Post date:** [August 28, 2004, 7:54pm UTC](https://forum.kirupa.com/t/perspective-depth/62525/1 "2004-08-28T19:54:17Z")

</div>

Hey people!

I’ve been searching the forum for this, I’m almost sure I saw a thread about it somewhere but can’t find it anywhere, so exuse me if I’m duplicating another thread…

I’ve got a little problem. I started working on this game yesterday and already bumped into a problem (take a look at the screenshot). All the (for now ugly) bushes and houses are being generated with a **for(i=…** statement with a random position to keep the gameplay different everytime you play it. Some bushes that are further away from our perspective should be _behind_the other bushes that are closer to us.

Is there anybody who knows a simple treatment to swap the depths of the movieclips which \_y positions \< than the \_y positions of the ones closer to us??

Thanks for any thoughts/help in advance!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2004, 8:12pm UTC](https://forum.kirupa.com/t/perspective-depth/62525/2 "2004-08-28T20:12:00Z")

</div>

what, we’re not allowed to see the name? 😛

Just use swapDepths with their \_y values.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2004, 10:11pm UTC](https://forum.kirupa.com/t/perspective-depth/62525/3 "2004-08-28T22:11:04Z")

</div>

Thanks, I guess it is the easiest way after all.  
This is what I did:

- I’ve put every tree name in an array.
- When the trees are generated I do a quick hitTest in a for(i… function to see if there are trees overlapping
- if the \_y of the target \< this.\_y and the depth \> this.\_getDepth() then it will swap it’s depth with the target.

It works great now, thanks man!

Btw, I just blurred the name to prevent words with the client I’m building it for. safety goes first hehe. 😉
