Perspective Depth

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 behindthe 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!!

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

Just use swapDepths with their _y values.

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. :wink: