33 lines
518 B
GDScript
33 lines
518 B
GDScript
extends Sprite
|
|
|
|
export var scroll_speed = 9
|
|
|
|
var moving = false
|
|
|
|
signal viewport_entered(object)
|
|
signal viewport_exited(object)
|
|
|
|
|
|
func start():
|
|
moving = true
|
|
|
|
|
|
func stop():
|
|
moving = false
|
|
|
|
|
|
func _physics_process(delta):
|
|
if moving:
|
|
move()
|
|
|
|
|
|
func move():
|
|
position.x -= scroll_speed
|
|
|
|
|
|
func _on_VisibilityNotifier2D_viewport_entered(viewport: Viewport) -> void:
|
|
emit_signal("viewport_entered", self)
|
|
|
|
|
|
func _on_VisibilityNotifier2D_viewport_exited(viewport: Viewport) -> void:
|
|
emit_signal("viewport_exited", self)
|