Hello Guest

Author Topic: Layer / Z-Order?  (Read 14304 times)

hima

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Layer / Z-Order?
« on: January 30, 2012, 07:54:08 am »
Is there a way to determine which sprite is on top of the others? Something like layer or z order?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Layer / Z-Order?
« Reply #1 on: January 30, 2012, 10:51:39 pm »
Assuming you're using an ortho camera, the z-distance to the camera dictates the z-order. The smaller the z value, the closer it is to the camera.

xenop

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Layer / Z-Order?
« Reply #2 on: February 02, 2012, 03:08:50 pm »
Hi there,

And what if you use a perspective camera?

Example: I have a tube where a arrow shoots out. If I place the arrow a little bit behind the tube. The sprites will glitch.

The arrow is in front of the tube in-game, but is placed behind the tube in the editor.

I want to use a perspective camera because I want a paralax effect.

I hope there is a solution for this.

thx


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Layer / Z-Order?
« Reply #3 on: February 03, 2012, 01:11:56 am »
Same principle applies with a perspective camera, but it'll be slightly more complicated - you will need to use Camera.WorldToScreenPoint and Camera.ScreenToWorldPoint to move objects. The glitching is unavoidable - the only solution is to move closer in Z.

I am preparing a new parallax sample using ortho cameras - it is much much simpler to set up and there is no chance of glitching like this. No promises, but I will try and post it on the forums sometime this weekend. This script will be in the next beta.

Cheers,
unikron

Bohdon

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Layer / Z-Order?
« Reply #4 on: February 07, 2012, 12:58:43 am »
We used a Render Queue Modifier script we made to change the renderQueue property of an object's material at run time.  Each modifier can be associated with a group so that you could easily change the depth of a group of objects.  Downfall is that you have to do the group sorting manually, but it works really effectively, no glitching and we use perspective cameras with completely flat characters.  We'll likely be putting up the Render Queue scripts on the asset store soon if people are interested...

xenop

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Layer / Z-Order?
« Reply #5 on: February 13, 2012, 11:04:30 am »
Any ETA when the paralax script will be available ?

greetz xenop

levelord

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Layer / Z-Order?
« Reply #6 on: March 14, 2012, 12:26:29 pm »
Is the Render Queue available?  I'm getting the same Z-order glitching with only 3 overlapping sprites.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Layer / Z-Order?
« Reply #7 on: March 14, 2012, 01:06:01 pm »
Have you tried the parallax script in the private support forum? That might help reduce z-order glitching significantly.

levelord

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Layer / Z-Order?
« Reply #8 on: March 14, 2012, 07:11:35 pm »
Just took a look at it, not sure if I understand, though.  I need 3 cameras with culling and whatnot just to insure one sprite consistantly occludes another sprite as they move around the scene?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Layer / Z-Order?
« Reply #9 on: March 14, 2012, 08:11:25 pm »
No, basically everything within one layer is displayed by one camera. Within the layer, sorting is pretty much perfect as it uses an ortho camera, and just tiny z differences are sufficient. The other two cameras display the foreground and background layers respectively. So 1 camera per layer, as many sprites as you want per layer, and use the parallax script to scale movement and simulate parallax on the other layers.

Hope that helps...