Hello Guest

Author Topic: Help! Sprites disappearing at different camera angles!  (Read 5275 times)

Arktor314

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Help! Sprites disappearing at different camera angles!
« on: May 28, 2013, 05:46:16 am »
I've got a perspective camera at an angle of 30 degrees from the horizontal. Everything was working fine until I tried swapping out the default terrain with new much more colorful 2D sprites, which has caused the other sprites to disappear frequently depending where the camera is located. (See below pictures: The sprite that the red arrow points at disappears when the camera moves slightly to the left.)



The sprites themselves are at the same height and parallel to the terrain (as shown).


I tried changing the camera's transparency sorting to orthographic, but that didn't help (possibly made it worse.) I reverted that and tried switching the camera to orthographic, but that didn't help. The only thing that does seem to help is changing the camera angle to orthographic AND pointing it down so it faces the terrain directly, but I really don't want to do that (everything so far has been designed based on an isometric angle.)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help! Sprites disappearing at different camera angles!
« Reply #1 on: May 28, 2013, 10:56:32 am »
The issue is that the objects centers are used to sort them, and this is based on the distance to the camera. Sorting in cases like this will not be reliable unless you do something about it.

1. In your case, the background sprites (green / tiles / etc) are solid. Why not use a solid material on them? This will ensure that they will get drawn before the transparent sprites. How to set up multiple materials: http://unikronsoftware.com/2dtoolkit/docs/1.92/tutorial/multiple_materials_in_a_sprite_collection.html

2. Use a second camera to force the foreground sprites to draw later. Create a second camera with the same parameters as the first, then use layer masks to draw the background into the first camera, and the foreground sprites into the second. You should use the camera depth option to make sure they draw in the proper order, and the second camera shouldn't clear anything at all.

In terms of performance #1 will give you better performance.

Arktor314

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Help! Sprites disappearing at different camera angles!
« Reply #2 on: May 28, 2013, 11:54:18 pm »
Thank you!