2D Toolkit Forum

2D Toolkit => Support => Topic started by: oug on June 05, 2015, 11:31:54 am

Title: [Solved] Sprites disappear and act weird when they are rotated
Post by: oug on June 05, 2015, 11:31:54 am
Hi guys,

First of all, amazing product, amazing service and a great experience all around. I've made a variety of 2D games with your product and it's been great since the start.

For now I am working on a TCG (a combination of HeartStone and Triple Triad) and I've run into an issue where the sprites of a card disappear when I try to rotate them. The issue is as follows:

I have a card that consists of a number of layered sprites. These sprites are layered through z-index (not through the sorting layers, ill explain why later) and the have a background, borderhighlight, title, flavourtext, some icons etc. Next to this the card has a back and a front (the idea is that I can use the card as a (pseudo) 3D gameobject and rotate them from laying down to laying up without a large hassle.

The card basically looks like this when viewed from 3D perspective:

Side (3D view) (the spacing between the sprites is slightly exaggerated)
(http://www.oneuppedgames.com/2dtoolkit/3d-side-view.jpg)

Front (2D view)
(http://www.oneuppedgames.com/2dtoolkit/2d-front-view.jpg)

Back (2D view)
(http://www.oneuppedgames.com/2dtoolkit/2d-back-view.jpg)

When I rotate this card in the Y-axis a strange behaviour occurs. The front layer (the one with alle the little visuals) behaves in a really strange way. It seems that the sprites don't follow the proper camera rules (or z-index rules). This is what happens when I rotate the card clockwise (over y-axis)

45 degrees clockwise (ignore the green border, this is the same as the blue one!)
(http://www.oneuppedgames.com/2dtoolkit/45cw-view.jpg)

135 degrees clockwise
(http://www.oneuppedgames.com/2dtoolkit/135cw-view.jpg)

215 degrees clockwise
(http://www.oneuppedgames.com/2dtoolkit/215cw-view.jpg)

305 degrees clockwise
(http://www.oneuppedgames.com/2dtoolkit/305cw-view.jpg)

Strange thing is that the three back layers (the back of the card, the background of the front of the card and the edge-highlight of the front of the card) act exactly as I want them to. When I move the front layer (with all the little icons) a lot more to the front (like 100-200) it suddenly works (however, the rotation looks really weird because there is now a visible distance between the background of the card and the front layer.

front layer 100-200 to the front and 45 degrees clockwise rotation  (ignore the green border, this is the same as the blue one!)
(http://www.oneuppedgames.com/2dtoolkit/45cw-100-view.jpg)

My question is: how do I fix this? Is even possible? I've also tried to do this when the sprites are all layered based on sorting layers and then it works fine. However, in that case I have the issue that I have to make sure that all the frontside sprites are hidden when the rotation exceeds 180 (and again show them again when the rotation exceeds 360).

Next to this I will have the issue that when there are a lot of cards in the game, I have to put every card on a different sorting layer (or keep switching all the sprites to different values within the same sorting layer).

Can anyone shine a light on this (the rotation issue as well as a more easy approach to this whole issue)?

Thank you all in advance!

OUG
Title: Re: Sprites disappear and act weird when they are rotated
Post by: unikronsoftware on June 06, 2015, 11:17:25 pm
It is quite easy to do this if you use sorting layers instead of Z position to sort the sprites. The only catch is you'll have to deal with overlapping cards yourself (you probably already do that using Z) and when a card spins > 180 degrees, the sorting order needs to be swapped around.
Title: Re: Sprites disappear and act weird when they are rotated
Post by: oug on June 08, 2015, 07:37:53 am
Yeah I was thinking that that might be the best solution.

Do you have an easy way to sort cards that are on top of each other? Can I dynamically add and remove new sorting layers or do you think it is better to just switch position within the sorting layer?
Title: Re: Sprites disappear and act weird when they are rotated
Post by: unikronsoftware on June 08, 2015, 07:49:15 am
Just use the offset inside the layer, no need for names layers
Title: Re: Sprites disappear and act weird when they are rotated
Post by: oug on June 08, 2015, 08:07:28 am
Cool thanks!