Godot动画系统:Tween节点

Godot Engine 3.2alpha

Godot中的Tween就类似于Unity插件Dotween或iTween的作用,主要用于对某些属性进行插值动画

使用实例

节点结构

Godot动画系统:Tween节点_第1张图片ball是一个MeshInstance节点和tween是一个Tween节点,ball上挂接了逻辑脚本

代码如下

extends MeshInstance

onready var tween:Tween = $"tween"


func _input(event):
	if event is InputEventMouseButton:
		if event.button_index == BUTTON_LEFT and event.pressed == true:
			var pos = translation
			var x = randi()%4 -2
			randomize()
			var z = randi()%4 -2
			tween.interpolate_property(self,"translation",pos,Vector3(pos.x + x ,0,pos.z + z),1.0,Tween.TRANS_BACK,Tween.EASE_IN)
			tween.start()

关键步骤其实只有两行代码

tween.interpolate_property(self,"translation",pos,Vector3(pos.x + x ,0,pos.z + z),1.0,Tween.TRANS_BACK,Tween.EASE_IN)
			

interpolate_property即给定起始点对某一个属性进行插值,本例中每次点击鼠标都给球一个随机位置,然后在1秒内让它移动过去

tween.start()#启动tween动画

启动Tween动画

效果图

Godot动画系统:Tween节点_第2张图片

你可能感兴趣的:(Godot笔记,#,Godot,基础,Godot,游戏开发)