• 2D
  • Tween with C#

Hi, I want to use a tween to move the X of a tag. I want to move the X from -352 to 0, so the title will enter the screen.

I think I'm doing everything right, I just have a problem with the "NodePath Property" argument. I don't know what I should put there, it's a chain but I don't know which one. ¿RectPosition.x?   The compilation is successful and the execution also but nothing moves, this does not work:

    messageLabel = GetNode<Label>("MessageLabel");
    tweenTitleLabel = GetNode<Tween>("MessageLabel/mueveTitulo");
    tweenTitleLabel.InterpolateProperty(messageLabel, "RectPosition.x", -352, 0, 1, 0, 0);
    tweenTitleLabel.Start();

This is the project, the script scene is "HUD": https://www.dropbox.com/s/p6fce9hca01khmd/dodge%20the%20creeps.rar?dl=0

I don't know what it is for C#, but I think the NodePath property argument for GDScript needs to be formatted something like this: InterpolateProperty(messageLabel, "rect_position:x", -352, 0, 1, 0, 0);

Though I am not totally sure if that will work or not.

Here are some links I found that might be helpful: Tween only x or y position of node? - Reddit What is the correct way of pass the NodePath property for a Tween? - Godot Q&A * What is the nodepath of Control's rect_position ? [SOLVED] - Godot Q&A

Hi, I've tried everything: "Rect: RectPosition" "RectPosition" "MessageLabel: Rect: RectPosition" "MessageLabel / Rect: RectPosition"

I saw those threads before but they didn't help me. I have been with this problem for 3 hours and I am still investigating.

    messageLabel = GetNode<Label>("MessageLabel");
    tweenTitleLabel = new Tween();
    tweenTitleLabel.InterpolateProperty(messageLabel, "Rect:RectPosition", new Vector2(-380, 272), new Vector2(0, 272), 2, 0, 0);
    tweenTitleLabel.Start();

Nothing.

I would simply create an AnimationPlayer and keyframe animate it, personally. If your coal is to have a start screen with an animated camera looking into a scene you could have the title be parented to the camera and then animate it in respect to that.

But I want to learn the tween. I would like to know why it doesn't work.

One thought that occurs is that the tween might be animating the object according to it's local space so that by the end of the animation the tweens X:0 might bring the object back to where it was located before the tween started. Mind, I haven't made use of tween in godot before.

That does not happen, the node is located where the interpolation moved it.

In this program nothing happens, maybe a bug of tween?

Ok, in this case the problem is addChild, Im not using addChild, addChild solve this problem.

The problem is how to reference the RectPosition property of a label in C #.

Ok, the problem has been fixed. It should be referred to as "rect_position" not "RectPosition".

Awesome, I'm glad you were able to figure it out. I would have thought that in C# it would use the same property name, but I guess the nodepath properties use the GDScript property name instead.

I changed the topic from a discussion to a question so you can mark the relevant post(s) as the answer(s) if you want, which may make it easier for others with the same issue to find this post.

@TwistedTwigleg said: Awesome, I'm glad you were able to figure it out. I would have thought that in C# it would use the same property name, but I guess the nodepath properties use the GDScript property name instead.

I changed the topic from a discussion to a question so you can mark the relevant post(s) as the answer(s) if you want, which may make it easier for others with the same issue to find this post.

If so, it also happens for other nodes, for example for position of the sprite node. I opened an issue to see if this should be fixed, I think the correct mode for C # should be "RectPosition".

Thanks to all for the help.