Godot Version
4.5.1.stable
Question
I have code that starts a tween. It shows a button with an airship icon that goes from one city to another. I have a button moving, because I eventually want to connect this button to a method someday.
I noticed that when the button is shown, it starts moving as intended. However, when I switch to a different scene, then go back to the world map, the tween doesn’t show anymore. I heard PathFollow2D is a better method, but I do not know how to assign the origin coordinate and the destination coordinate to the PathFollow2D for the button to follow it. I also do not know how to write the code where multiple PathFollow2D nodes can be made, in case the player wants to “launch” multiple airships.
Below is the code I have so far:
func create_airship_icon():
var airship = Button.new()
#Spawns new airship button in World Map
airship.icon = load("res://sprites/Airship_icon.png")
airship.flat = true
var origin_vector = Vector2(map_to_local(Globals.cities[Globals.selected_city][0]))
airship.position = origin_vector
add_child(airship)
#Replace the random selecting of cities with a menu of available cities the player can choose from
var destination_vector = Vector2(map_to_local(Globals.cities[Globals.selected_destination_city][0]))
var final_distance = origin_vector.distance_to(destination_vector)
#Moves the spawned airship button from the origin to the destination cities
var tween = airship.create_tween()
tween.tween_property(airship, "position", destination_vector, final_distance * speed_multiplier)
await tween.finished
airship.queue_free()
I’m guessing the tween code has to be replaced, but I don’t know what code would work as an alternate solution?