如何让godot无限背景滚动
How to make godot infinite background scroll
在 godot 中我有 ParallaxLayer
extends ParallaxLayer
var motion = Vector2(-50, 0)
var start_pos = Vector2()
var speed = -50
# Called when the node enters the scene tree for the first time.
func _ready():
set_mirroring(motion)
pass
func _process(delta):
speed -= 5
set_motion_offset(motion+Vector2(speed,0))
此代码使背景滚动但不是无限
滚动到末尾时不知道要做什么
官方文档说我应该用set_mirroring
有人可以告诉我如何使用这个功能吗?
或者我应该去哪里了解更多信息?
镜像需要一个 Vector2 值,它是镜像“偏移”的 XY 坐标。通常,此值是您用作背景的图像的高度或宽度(通常与 window 大小相对应),具体取决于您要镜像的方向。下面的示例代码假定 window 大小为 1080x1920,ParallaxLayer 在 Y 轴上进行镜像。
extends ParallaxLayer
func _ready():
set_mirroring(motion_mirroring)
func _process(delta):
motion_mirroring = Vector2(0,1920)
在 godot 中我有 ParallaxLayer
extends ParallaxLayer
var motion = Vector2(-50, 0)
var start_pos = Vector2()
var speed = -50
# Called when the node enters the scene tree for the first time.
func _ready():
set_mirroring(motion)
pass
func _process(delta):
speed -= 5
set_motion_offset(motion+Vector2(speed,0))
此代码使背景滚动但不是无限
滚动到末尾时不知道要做什么
官方文档说我应该用set_mirroring
有人可以告诉我如何使用这个功能吗?
或者我应该去哪里了解更多信息?
镜像需要一个 Vector2 值,它是镜像“偏移”的 XY 坐标。通常,此值是您用作背景的图像的高度或宽度(通常与 window 大小相对应),具体取决于您要镜像的方向。下面的示例代码假定 window 大小为 1080x1920,ParallaxLayer 在 Y 轴上进行镜像。
extends ParallaxLayer
func _ready():
set_mirroring(motion_mirroring)
func _process(delta):
motion_mirroring = Vector2(0,1920)