Ability to flip horizontally or vertically TextureRect

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By salvob

Wouldn’t be useful having the option to flip a textureRect ?
Since it is a Control Node and it can be very useful in creating UI, but there is no way at all to flip the Node (unless you use rect_scale , but this does not work when inside Containers like HBOX or VBOX)

What do you guys think about it?

:bust_in_silhouette: Reply From: flurick

It would be handy, you could make it work by parenting the TextureRect to a Control with a script like this.

extends Control

export var flipped_h = false
export var flipped_v = false

func _ready():
	if flipped_h:
		$TextureRect.rect_scale.y *= -1
		$TextureRect.rect_position.y = $TextureRect.rect_size.y
	if flipped_v:
		$TextureRect.rect_scale.x = -1
		$TextureRect.rect_position.x = $TextureRect.rect_size.x

Thank you, i didn’t know that scale -1 would flip the texture.

mustapha | 2019-03-31 14:22

:bust_in_silhouette: Reply From: sleepprogger

Another possibility would be to get the image from the texture which has the flip_x and flip_y methods.
Then you can create a new ImageTexture from the flipped version and set that as texture for the texture_rect.

:bust_in_silhouette: Reply From: sangress

Another option is to set the pivot to center and then rotate rect 180 degrees.
See in the image below:

Godot flip texture_rect

This doesn’t work if the node is part of a container.

blurrred | 2022-06-04 00:49