Tween with C#

TheMnkTheMnk Posts: 51Member
edited November 2019 in 2D

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 the creeps.rar?dl=0


Tags :

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 3,525Admin

    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:

  • TheMnkTheMnk Posts: 51Member

    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.

  • MegalomaniakMegalomaniak Posts: 3,001Admin

    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.

  • TheMnkTheMnk Posts: 51Member

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

  • MegalomaniakMegalomaniak Posts: 3,001Admin

    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.

  • TheMnkTheMnk Posts: 51Member

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

  • TheMnkTheMnk Posts: 51Member
    edited November 2019

    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.

  • TheMnkTheMnk Posts: 51Member
    edited November 2019

    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".

  • TwistedTwiglegTwistedTwigleg Posts: 3,525Admin

    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.

  • TheMnkTheMnk Posts: 51Member
    edited November 2019

    @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.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file