Godot原生方法

CS
GetTree().CreateTween()
	.TweenProperty(@GodotObject, "属性名称", 目标值, 时间)
	.SetEase(Tween.EaseType.In /* 缓动类型 */)
	.SetTrans(Tween.TransitionType.Sine /* 过渡类型 */)
	.Finished += () => { /* 结束回调 */ };
点击展开查看更多

GTweensGodot

基本用法

引入命名空间

CS
using GTweensGodot.Extensions;
点击展开查看更多

部分示例

CS
// ModulateAlpha
@CanvasItem.TweenModulateAlpha(1, 0.25f)
	.Play();

// Position
@Node2D.TweenPosition(new Vector2(100, 0), 3)
	.SetEasing(Easing.InOutCubic)
	.Play();
点击展开查看更多

自定义Tween

官方未支持的类型、属性需要自定义 函数需要是公开的、静态的,写在哪都行

CS
public static GTweens.Tweens.GTween TweenXXX(
		T target /* 目标对象 */,
		V to /* 目标值 */,
		float duration
	) {
    return GTweenGodotExtensions.Tween(
        () => {
	        // 获取值
	        // 可以理解成属性的getter
        },
        current => {
	        // 设置值
	        // 可以理解成属性的setter
        },
        to,
        duration,
        GodotObjectExtensions.GetGodotObjectValidationFunction(target)
    );
}
点击展开查看更多

示例:Control的CustomMinimumSize属性

CS
public static GTweens.Tweens.GTween TweenCustomMinimumSize(Control target, Vector2 to, float duration) {
    return GTweenGodotExtensions.Tween(
        () => target.CustomMinimumSize,
        current => target.CustomMinimumSize = current,
        to,
        duration,
        GodotObjectExtensions.GetGodotObjectValidationFunction(target)
    );
}
点击展开查看更多

版权声明

作者: Chaim

链接: https://chaim.eu.org/posts/%E4%BB%A3%E7%A0%81%E6%8E%A7%E5%88%B6%E7%9A%84%E5%8A%A8%E7%94%BB/

许可证: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

开始搜索

输入关键词搜索文章内容

↑↓
ESC
⌘K 快捷键