How to animate gui rotation

Hello!

I’m trying to animate gui rotation, but i see this
I enter the parameters


In editor i see

and in the game I see it

Same if i try to use code

gui.animate(self.cards[1], "rotation.y", 30, gui.EASING_LINEAR, 3)
2 Likes

It looks like it has to do with the “near and far” planes being too narrow while rendering the GUI. Essentially the card might be rotated correctly, but most of it is outside the visible area (back and forth, aka near and far)!

By default in Defold, the near and far values are set to -1 and 1, you can verify this yourself inside the default.render_script file on this line;

    render.set_projection(vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1))

The last two arguments are near and far!

You could try to change this to something bigger, in your case it the values needs to be high enough to include the width of the rotated card… So let’s say you card is 100 pixels in width, something like this might work:

    render.set_projection(vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -50, 50))

You should be able to temporarily modify the default renderscript with these values and Build and launch to see if it works.

But since the builtins files can only be temporarily modified, you will need to make a copy of the renderscript to do any final changes! Make sure to also make a copy of the default.render file, and point it to your copied render script, and lastly update your game.project file to use your copy of the default.render file!

5 Likes

Works great!
Does it have any effect on performance?
Thanks!

No, but on Z precision if you crank the values up too much.

3 Likes