class_propertytweener.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/PropertyTweener.xml.
  6. .. _class_PropertyTweener:
  7. PropertyTweener
  8. ===============
  9. **Inherits:** :ref:`Tweener<class_Tweener>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Interpolates an :ref:`Object<class_Object>`'s property over time.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. **PropertyTweener** is used to interpolate a property in an object. See :ref:`Tween.tween_property()<class_Tween_method_tween_property>` for more usage information.
  15. The tweener will finish automatically if the target object is freed.
  16. \ **Note:** :ref:`Tween.tween_property()<class_Tween_method_tween_property>` is the only correct way to create **PropertyTweener**. Any **PropertyTweener** created manually will not function correctly.
  17. .. rst-class:: classref-reftable-group
  18. Methods
  19. -------
  20. .. table::
  21. :widths: auto
  22. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`PropertyTweener<class_PropertyTweener>` | :ref:`as_relative<class_PropertyTweener_method_as_relative>`\ (\ ) |
  24. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`PropertyTweener<class_PropertyTweener>` | :ref:`from<class_PropertyTweener_method_from>`\ (\ value\: :ref:`Variant<class_Variant>`\ ) |
  26. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`PropertyTweener<class_PropertyTweener>` | :ref:`from_current<class_PropertyTweener_method_from_current>`\ (\ ) |
  28. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`PropertyTweener<class_PropertyTweener>` | :ref:`set_custom_interpolator<class_PropertyTweener_method_set_custom_interpolator>`\ (\ interpolator_method\: :ref:`Callable<class_Callable>`\ ) |
  30. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`PropertyTweener<class_PropertyTweener>` | :ref:`set_delay<class_PropertyTweener_method_set_delay>`\ (\ delay\: :ref:`float<class_float>`\ ) |
  32. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`PropertyTweener<class_PropertyTweener>` | :ref:`set_ease<class_PropertyTweener_method_set_ease>`\ (\ ease\: :ref:`EaseType<enum_Tween_EaseType>`\ ) |
  34. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`PropertyTweener<class_PropertyTweener>` | :ref:`set_trans<class_PropertyTweener_method_set_trans>`\ (\ trans\: :ref:`TransitionType<enum_Tween_TransitionType>`\ ) |
  36. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  37. .. rst-class:: classref-section-separator
  38. ----
  39. .. rst-class:: classref-descriptions-group
  40. Method Descriptions
  41. -------------------
  42. .. _class_PropertyTweener_method_as_relative:
  43. .. rst-class:: classref-method
  44. :ref:`PropertyTweener<class_PropertyTweener>` **as_relative**\ (\ ) :ref:`🔗<class_PropertyTweener_method_as_relative>`
  45. When called, the final value will be used as a relative value instead.
  46. \ **Example:** Move the node by ``100`` pixels to the right.
  47. .. tabs::
  48. .. code-tab:: gdscript
  49. var tween = get_tree().create_tween()
  50. tween.tween_property(self, "position", Vector2.RIGHT * 100, 1).as_relative()
  51. .. code-tab:: csharp
  52. Tween tween = GetTree().CreateTween();
  53. tween.TweenProperty(this, "position", Vector2.Right * 100.0f, 1.0f).AsRelative();
  54. .. rst-class:: classref-item-separator
  55. ----
  56. .. _class_PropertyTweener_method_from:
  57. .. rst-class:: classref-method
  58. :ref:`PropertyTweener<class_PropertyTweener>` **from**\ (\ value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_PropertyTweener_method_from>`
  59. Sets a custom initial value to the **PropertyTweener**.
  60. \ **Example:** Move the node from position ``(100, 100)`` to ``(200, 100)``.
  61. .. tabs::
  62. .. code-tab:: gdscript
  63. var tween = get_tree().create_tween()
  64. tween.tween_property(self, "position", Vector2(200, 100), 1).from(Vector2(100, 100))
  65. .. code-tab:: csharp
  66. Tween tween = GetTree().CreateTween();
  67. tween.TweenProperty(this, "position", new Vector2(200.0f, 100.0f), 1.0f).From(new Vector2(100.0f, 100.0f));
  68. .. rst-class:: classref-item-separator
  69. ----
  70. .. _class_PropertyTweener_method_from_current:
  71. .. rst-class:: classref-method
  72. :ref:`PropertyTweener<class_PropertyTweener>` **from_current**\ (\ ) :ref:`🔗<class_PropertyTweener_method_from_current>`
  73. Makes the **PropertyTweener** use the current property value (i.e. at the time of creating this **PropertyTweener**) as a starting point. This is equivalent of using :ref:`from()<class_PropertyTweener_method_from>` with the current value. These two calls will do the same:
  74. .. tabs::
  75. .. code-tab:: gdscript
  76. tween.tween_property(self, "position", Vector2(200, 100), 1).from(position)
  77. tween.tween_property(self, "position", Vector2(200, 100), 1).from_current()
  78. .. code-tab:: csharp
  79. tween.TweenProperty(this, "position", new Vector2(200.0f, 100.0f), 1.0f).From(Position);
  80. tween.TweenProperty(this, "position", new Vector2(200.0f, 100.0f), 1.0f).FromCurrent();
  81. .. rst-class:: classref-item-separator
  82. ----
  83. .. _class_PropertyTweener_method_set_custom_interpolator:
  84. .. rst-class:: classref-method
  85. :ref:`PropertyTweener<class_PropertyTweener>` **set_custom_interpolator**\ (\ interpolator_method\: :ref:`Callable<class_Callable>`\ ) :ref:`🔗<class_PropertyTweener_method_set_custom_interpolator>`
  86. Allows interpolating the value with a custom easing function. The provided ``interpolator_method`` will be called with a value ranging from ``0.0`` to ``1.0`` and is expected to return a value within the same range (values outside the range can be used for overshoot). The return value of the method is then used for interpolation between initial and final value. Note that the parameter passed to the method is still subject to the tweener's own easing.
  87. .. tabs::
  88. .. code-tab:: gdscript
  89. @export var curve: Curve
  90. func _ready():
  91. var tween = create_tween()
  92. # Interpolate the value using a custom curve.
  93. tween.tween_property(self, "position:x", 300, 1).as_relative().set_custom_interpolator(tween_curve)
  94. func tween_curve(v):
  95. return curve.sample_baked(v)
  96. .. code-tab:: csharp
  97. [Export]
  98. public Curve Curve { get; set; }
  99. public override void _Ready()
  100. {
  101. Tween tween = CreateTween();
  102. // Interpolate the value using a custom curve.
  103. Callable tweenCurveCallable = Callable.From<float, float>(TweenCurve);
  104. tween.TweenProperty(this, "position:x", 300.0f, 1.0f).AsRelative().SetCustomInterpolator(tweenCurveCallable);
  105. }
  106. private float TweenCurve(float value)
  107. {
  108. return Curve.SampleBaked(value);
  109. }
  110. .. rst-class:: classref-item-separator
  111. ----
  112. .. _class_PropertyTweener_method_set_delay:
  113. .. rst-class:: classref-method
  114. :ref:`PropertyTweener<class_PropertyTweener>` **set_delay**\ (\ delay\: :ref:`float<class_float>`\ ) :ref:`🔗<class_PropertyTweener_method_set_delay>`
  115. Sets the time in seconds after which the **PropertyTweener** will start interpolating. By default there's no delay.
  116. .. rst-class:: classref-item-separator
  117. ----
  118. .. _class_PropertyTweener_method_set_ease:
  119. .. rst-class:: classref-method
  120. :ref:`PropertyTweener<class_PropertyTweener>` **set_ease**\ (\ ease\: :ref:`EaseType<enum_Tween_EaseType>`\ ) :ref:`🔗<class_PropertyTweener_method_set_ease>`
  121. Sets the type of used easing from :ref:`EaseType<enum_Tween_EaseType>`. If not set, the default easing is used from the :ref:`Tween<class_Tween>` that contains this Tweener.
  122. .. rst-class:: classref-item-separator
  123. ----
  124. .. _class_PropertyTweener_method_set_trans:
  125. .. rst-class:: classref-method
  126. :ref:`PropertyTweener<class_PropertyTweener>` **set_trans**\ (\ trans\: :ref:`TransitionType<enum_Tween_TransitionType>`\ ) :ref:`🔗<class_PropertyTweener_method_set_trans>`
  127. Sets the type of used transition from :ref:`TransitionType<enum_Tween_TransitionType>`. If not set, the default transition is used from the :ref:`Tween<class_Tween>` that contains this Tweener.
  128. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  129. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  130. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  131. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  132. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  133. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  134. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  135. .. |void| replace:: :abbr:`void (No return value.)`