Access other objects, and play animations.

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

Hello, how can i call animations of other objects?

I’ve tried this, but it doesn’t work.

func on_click():
    hand_c.get_node("anim").play("fade_out")

I’ve these objects:

Area2D
hand_c
hand_o
hand_s

All theses nodes inherit hand

hand.tscn code:

extends Area2D


func _ready():
	pass


func _on_hand_mouse_entered():
	
	$anim.play("zoom_in")
	
	pass # replace with function body

func _on_hand_mouse_exited():
	
	$anim.play("zoom_out")
	
func fade_out():
	
	$anim.play("fade_out")

func _on_hand_input_event(viewport, event, shape_idx):
	
	if event is InputEventMouseButton \
    and event.button_index == BUTTON_LEFT \
    and event.is_pressed():
		
        self.on_click()

How can i call this “fade_out” animation, from one object to other?

Example:

when the user clicks on one hand, the other hands will fade out.

Oh and i forgot to say, it’s a rock-paper-scissors game.

:bust_in_silhouette: Reply From: p7f

You could add a method in your hand script called for instance “play_anim()”, and in there you use $anim.play(“fade_out”). You can even pass the animation wanted as an argument to play_anim(). So, instead of:

hand_c.get_node("anim").play("fade_out")

You call

hand_c.play_anim()

Or something like that. A minimal example worked in my pc.

Thank you, it was very helpful.

CaueHenrique | 2018-12-14 18:44

Glad to be helpful!

p7f | 2018-12-14 18:44