Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 5506f1c

Browse files
committed
Add new option to parallax node 'position_as_offset'
Useful for offsetting a parallax node by itself.
1 parent 5e6080e commit 5506f1c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

addons/parallax_node/parallax_node.gd

100644100755
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,34 @@ class_name ParallaxNode extends Node2D
1010
## the screen, and 0.5 is like 1 but it moves slower.
1111
@export var parallax_factor: Vector2 = Vector2.ONE
1212

13+
## Whether or not to use the position set for the node on ready
14+
## as an internal offsetting system.
15+
@export var position_as_offset: bool = false
16+
1317
## Whether or not to automatically get the current camera
1418
## every frame, could be beneifical to keep this off in certain
1519
## circumstances, but is on by default for maximum performance.
1620
@export var ignore_camera_changes: bool = true
1721

1822
## Internal variable used to track the current camera.
19-
var camera: Camera2D
23+
var _camera: Camera2D
24+
var _offset: Vector2 = Vector2.ZERO
2025

2126

2227
func _ready() -> void:
23-
camera = get_viewport().get_camera_2d()
28+
_camera = get_viewport().get_camera_2d()
29+
30+
if position_as_offset:
31+
_offset = position
2432

2533

2634
func _process(delta: float) -> void:
2735
if not ignore_camera_changes:
28-
camera = get_viewport().get_camera_2d()
36+
_camera = get_viewport().get_camera_2d()
2937

30-
if camera == null:
38+
if _camera == null:
3139
position = Vector2.ZERO
3240
return
3341

34-
position = (camera.get_screen_center_position() - (get_viewport_rect().size / 2.0)) * (Vector2.ONE - parallax_factor)
42+
position = _offset + (_camera.get_screen_center_position() - \
43+
(get_viewport_rect().size / 2.0)) * (Vector2.ONE - parallax_factor)

addons/parallax_node/plugin.cfg

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="ParallaxNode"
44
description="Alternative new node to the built-in ParallaxBackground & ParallaxLayer system, one that is simpler and is not affected by the camera's zoom."
55
author="Midnight"
6-
version="0.0.2"
6+
version="0.0.3"
77
script="plugin.gd"

0 commit comments

Comments
 (0)