子场景可以“幻灯片”吗?在运行时进入父场景?
是否可以在运行时将场景(输入Control
)“滑动”到场景中间。
我有一个“父”场景,中间有一个空白区域。我想将一系列场景“滑动”到父场景的中央空白区域。
我想做这样的事情,但是使用动画:
var qi = load("res://Child1.tscn").instance()
qi.get_node("/root/Child1")
$VBoxContainer/MiddleArea.add_child(qi)
然后,使用不同或相同的数据在相同或另一种类型的场景中滑动:
var qi = load("res://Child1.tscn").instance()
qi.get_node("/root/Child1")
$VBoxContainer/MiddleArea.add_child(qi)
该序列由数据库中的数据驱动,因此在设计时不可预测场景可能需要出现的顺序的时间。
Is it possible to "slide" a scene (type Control
) into the middle of a scene at runtime.
I have a "parent" scene, with a blank area in the middle. I would like to "slide" a sequence of scenes into the central blank area of the parent scene.
I want to do something like this, but with animation:
var qi = load("res://Child1.tscn").instance()
qi.get_node("/root/Child1")
$VBoxContainer/MiddleArea.add_child(qi)
Then later on, slide in the same, or another type of scene, with different or the same data:
var qi = load("res://Child1.tscn").instance()
qi.get_node("/root/Child1")
$VBoxContainer/MiddleArea.add_child(qi)
The sequence is driven by data in a database, so its not predictable at design time what sequence of scenes might need to appear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,你想要的可以用
Tween
来完成。因此,首先将 Tween 添加到场景树中。我们可以将它保存在一个变量中,如下所示:
然后我们可以使用它来制作一个简单的动画:
此代码将为场景的位置设置动画。起始位置
Vector2(-qi.rect_size.x, qi.rect_position.y)
位于屏幕左侧。最终位置是场景在动画之前的位置。如果您要在这一行循环中添加多个以等待动画结束,然后再执行下一个:
如果您要将场景添加到设置场景位置的容器中,您可能需要像这样添加它this:
这里
qi.modulate = Color.transparent
将使场景不可见。然后我们将其添加到容器中,并使用 yield(get_tree(), "idle_frame") 等待一帧,在此期间容器设置场景的位置。最后我们使用 qi.self_modulate = Color.white 来恢复可见性。 我们必须使场景不可见,这样它就不会出现一帧然后消失然后进行动画处理。我们不使用visible
因为容器可能会跳过定位场景。If I understand correctly, what you want can be done with a
Tween
.So, first off all add
Tween
to the scene tree. We can hold it in a variable like this:Then we can use it to make a simple animation:
This code will animate the position of the scene. The starting position
Vector2(-qi.rect_size.x, qi.rect_position.y)
is just outside of the screen to the left. And the final position is wherever the scene is positioned before the animation.If you are adding multiple in a loop at this line to await the end of the animation before doing the next one:
And if you are adding the scene to a container that is setting the position of the scene, you might want to add it like this:
Here
qi.modulate = Color.transparent
will make the scene invisible. Then we add it to the container, and wait for one frame withyield(get_tree(), "idle_frame")
, during which the container set the position of the scene. And finally we useqi.self_modulate = Color.white
to restore the visibility. We have to make the scene invisible so it does not appear for one frame just to disappear and then be animated. And we don't usevisible
because the container might skip positioning the scene.