Rotate TouchScreenButton around center

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

Is there a way to rotate TouchScreenButton around center?

I would like to add Tween to wobble the button on press and can’t figure out how to do rotation around center of the button.

enter image description here

I can probably do it ugly way:

	

tween.interpolate_property(self, "rotation_degrees", 0, -20, 0.1, Tween.TRANS_BOUNCE,Tween.EASE_IN)
tween.interpolate_property(self, "position:x", self.position.x, self.position.x-40, 0.1, Tween.TRANS_BOUNCE,Tween.EASE_IN)
tween.interpolate_property(self, "position:y", self.position.y, self.position.y+50, 0.1, Tween.TRANS_BOUNCE,Tween.EASE_IN)
		tween.start()

But it is quite cumbersome to hardcode those position changes.

Is there something “origin” based? Like

self.transform.origin = Vector2(position.x/2, position.y/2)
self.rotation = 1
:bust_in_silhouette: Reply From: kidscancode

Set the rect_pivot_offset:

Thx. But there is no such property for a TouchScreenButton – it is not Control.

habamax | 2019-08-30 14:22

Ah - sorry, I read “Button” and thought we were talking about Controls.

How about making the button a child of a Node2D and using that as your pivot?

kidscancode | 2019-08-30 14:33

Did exactly that :wink:

habamax | 2019-09-01 10:14

:bust_in_silhouette: Reply From: habamax

I end up making

  • Node2D->TouchScreenButton
  • Center TouchScreenButton within Node2D
  • rotate Node2D