Double-sided sprites

Hi
I’d like to render a playing card as a single sprite. Cards have both a front and a back texture. In Unity, I was able to handle this at the material level. Is there something similar in defold? I’d rather not have 2 sprites for every card if I can help it.

Many thanks

You should have a sigle sprite and change what the sprite shows using sprite.play_flipbook. Please note that a flipbook here may also be a single image.

Hope this helps.

1 Like

OK. I will give that a go. Thanks for the reply.

How did you do it in Unity at the material level? There’s probably other options available by using UV offsets and stuff like that

In general, in Unity you can change everything in runtime. As far as I understand, a material in unity keeps track of the texture region to show (a sprite). It is way different from Defold for which “material” is very close to shaders.

Just my idea…

In Unity you can set the material up to display a different texture for the back face and front face of a sprite. It’s useful for billboarding things with a back and a front and for my particular use case. If you rotate the sprite around the x or y axis you get shown a different side.

I see, you should be able to calculate that in a shader, but it will be easier when we ship multitexture support for sprites (which should be available in the next version).

As a matter of fact, you can use gl_FrontFacing in a fragment shader to deduce which texture to sample from: gl_FrontFacing - OpenGL 4 Reference Pages

7 Likes

This is good to know. Is there a roadmap that has this on?

Hm, we don’t really have roadmaps per se, but here’s the issue:

It’s almost done afaik, so should be ready in the next release!

2 Likes