4
\$\begingroup\$

So simple question that I just can't find an answer to, how do I use Godot's _draw function to draw textures rotated at an angle (more specifically how do I get them turned completely 90° onto their side).

\$\endgroup\$
3
  • \$\begingroup\$ When you say "how do I get them turned completely 90° onto their side", do you mean simply rotate them by 90°? Have you tried rotating the object that contains that texture instead? \$\endgroup\$ Commented Oct 17, 2019 at 10:11
  • \$\begingroup\$ That is something I've considered but I'm trying to do this within the context of my wider UI, all of which is drawn by my camera in it's _draw function, so I was hoping there was a solution within the _draw function itself so I wouldn't have to start breaking up my UI into different nodes. \$\endgroup\$ Commented Oct 17, 2019 at 10:51
  • 1
    \$\begingroup\$ I have only a little experience with Godot, but from other game engines I've used, the general idea is that you use Game Objects to move things around, including textures, and not handling the drawing of them manually. I'm not sure if that's different on Godot. \$\endgroup\$ Commented Oct 17, 2019 at 11:02

1 Answer 1

5
\$\begingroup\$

You can use draw_set_transform to set the position, rotation, and scale of all following draw calls:

extends Control

func _draw():
    var icon = preload("res://icon.png")
    draw_texture(icon, Vector2(0, 0))
    draw_set_transform(Vector2(100, 100), PI / 2.0, Vector2(1, 1))
    draw_texture(icon, Vector2(0, 0))
    draw_set_transform(Vector2(200, 200), PI, Vector2(2, 2))
    draw_texture(icon, Vector2(0, 0))

example output

However, as @TomTsagk hinted in the comments, _draw is only necessary if you have custom needs. In general, building your UI out of Control components will give you more out-of-the-box functionality. For example, you could use a TextureRect to draw a texture in your UI, which has a set_rotation method.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .