Hello Guest

Author Topic: Can't change draw order of sprites  (Read 4747 times)

ziggyeye

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Can't change draw order of sprites
« on: June 18, 2013, 03:26:23 am »
I'm changing the draw order of some sprites in code and through the editor but nothing seems to happen.

In code, I add sprites onto a GameObject I have on the scene.

sprite = (GameObject)Instantiate(spritePrefab);
sprite.transform.parent = this.transform;
sprite.transform.position = new Vector3(160, 240, -1.0f);
sprite.transform.localScale = new Vector3(1,1,0);

sprite2 = (GameObject)Instantiate(spritePrefab2);
sprite2.transform.parent = this.transform;
sprite2.transform.position = new Vector3(160, 240, -2.0f);
sprite2.transform.localScale = new Vector3(1,1,0);

However, when I run it, I notice the sprites have a z of 0 and changing the z in both editor and code does nothing. Changing x,y works fine so I know the sprites are hooked in correctly.

Any help would be appreciated.

Thanks.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Can't change draw order of sprites
« Reply #1 on: June 18, 2013, 10:37:25 am »
Your z = 0 because localScale.z = 0.
Leave it at 1 and it should appear at the correct position.
Probably on the parent object too.

ziggyeye

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Can't change draw order of sprites
« Reply #2 on: June 18, 2013, 06:40:44 pm »
That worked! Was driving me crazy.
Thank you for the help!