Created
January 31, 2020 13:36
-
-
Save andrew-wilkes/c0c519ccd2628d888aedbcbf6dd2e94c to your computer and use it in GitHub Desktop.
GDScript side scroll code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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