Trouble with Tweens

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By elopez0911
:warning: Old Version Published before Godot 3 was released.

Hello all,

So coming from Unity I wanted an engine that was less bloated and more geared towards 2D. I am literally a few days into this so this could be a bonehead question.

So I downloaded Godot 3 and created a Node2D with a Sprite and Tween as children:

Node2D
–Sprite
–Tween

The sprite is the blue godot included image. Then put a script on the Node2D:

extends Node2D

onready var tween = get_node("Tween")
onready var sprite = get_node("Sprite")

func _ready():
	tween.interpolate_property(sprite, "transform/scale", Vector2(10,10), Vector2(1,1), 1.0, Tween.TRANS_ELASTIC, Tween.EASE_OUT)
	tween.start()
	pass

But when I run it, nothing happens. As a sanity check, I downloaded version 2.1.4 and created the same scenario and script, and when I run it the animation plays fine. I can’t imagine such a ‘simple’ thing would be broken from v2 to v3 so hoping someone can provide some guidance.

:bust_in_silhouette: Reply From: kidscancode

One of the big changes from 2.1 to 3.0 was in naming things. The property name is now “scale” (which you can see by hovering over the property in the Inspector.

In addition, here’s a couple of other tips:

  • GDScript in 3.0 includes a shorthand to avoid typing all those get_node()s. You use $<node_name> to mean the same thing. In my mind, it leads to much more readable code.

  • pass is a placeholder for an empty function. You should delete it.

For example, here’s how I would rewrite this script for 3.0:

extends Node2D

func _ready():
    $Tween.interpolate_property($Sprite, "scale", Vector2(10,10), Vector2(1,1), 1.0, Tween.TRANS_ELASTIC, Tween.EASE_OUT)
    $Tween.start()

Thank you so much! Looking forward to watching some of your videos =)

elopez0911 | 2018-01-04 02:38

whew I’ve been looking for this answer for weeks.

Redvim | 2018-12-27 05:32