Skip to content

Instantly share code, notes, and snippets.

@andrew-wilkes
Created January 31, 2020 13:36
Show Gist options
  • Save andrew-wilkes/c0c519ccd2628d888aedbcbf6dd2e94c to your computer and use it in GitHub Desktop.
Save andrew-wilkes/c0c519ccd2628d888aedbcbf6dd2e94c to your computer and use it in GitHub Desktop.
GDScript side scroll code
extends Node2D
const SPEED = 100
var max_x
var pos = 0
var terrain
var p_bg
var p_layer
func _ready():
p_bg = $ParallaxBackground
terrain = $ParallaxBackground/ParallaxLayer/ProceduralTerrain
max_x = terrain.end_pos
p_layer = $ParallaxBackground/ParallaxLayer
p_layer.motion_mirroring.x = max_x
func _process(delta):
pos -= SPEED * delta
if pos < 0:
pos = max_x
#p_layer.motion_offset.x = pos
#p_bg.scroll_offset.x = pos
$ParallaxBackground/ParallaxLayer/Camera2D.offset.x = pos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment