如何从key中获取属性名称?
我正在尝试获取从动画播放器节点更改的所有属性和值的列表,
但是如何获取动画键正在更改的节点的属性名称?
也许是这样的:
var ani=aniplayer.get_animation('running');
for i in range(0,ani.get_track_count()):
var key_idx=ani.track_find_key(i,0,0);
print("property=>",ani.get_key_property(i,key_idx)," new value=>",ani.track_get_key_value(i,key_idx));
I'm trying to get a list of all the properties and the values that are being changed from an animation player node,
but how do I get the property name of node that the animation key is changing?
maybe something like this:
var ani=aniplayer.get_animation('running');
for i in range(0,ani.get_track_count()):
var key_idx=ani.track_find_key(i,0,0);
print("property=>",ani.get_key_property(i,key_idx)," new value=>",ani.track_get_key_value(i,key_idx));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您有一个动画播放器:
您可以通过名称获得动画:
如您所知,您可以获取动画的轨道数:
当然我们可以循环:
让我们看看,您想知道属性是什么正在设置。要获取属性,我们需要获取路径,并从那里提取属性:
附录:
还有另一种方法可以从
NodePath
获取属性路径:get_concatenated_subnames
。或者我们可以用
get_subname
。这就是属性名称:
我想现在正是让大家注意
AnimationPlayer
可以为子属性设置动画这一事实的好时机。使用get_subname(0)
您可以获取属性,但不能获取子属性。例如,您不必为
position
设置动画,您可以为position.y
设置动画,并且可以通过在动画面板中轨道名称的末尾。 我在其他地方更详细地描述了如何做到这一点。在本例中get_subname( 0)
将为您提供position
,但get_concatenated_subnames()
将为您提供position:y
。Let us say you have an animation player:
And you get an animation by name:
As you know you can get the number of tracks the animations has:
And, of course we can loop:
Let us see, you want to know what property is being set. To get the property, we need to get the path, and extract the property from there:
Addendum:
There is another way to get the property path from a
NodePath
:get_concatenated_subnames
.Or we can get the elements separated with
get_subname
.So this is the property name:
I guess this is good time as any to bring attention to the fact that
AnimationPlayer
can animate sub-properties. Withget_subname(0)
you get the property, but not the sub-property.For example, you don't have to animate
position
, you can animateposition.y
and you would do that by adding:y
at the end of the track name in the Animation panel. I describe how to do it with more detail elsewhere. In this caseget_subname(0)
will give youposition
, butget_concatenated_subnames()
will give youposition:y
.