This repository was archived by the owner on Jun 28, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -10,25 +10,34 @@ class_name ParallaxNode extends Node2D
10
10
## the screen, and 0.5 is like 1 but it moves slower.
11
11
@export var parallax_factor : Vector2 = Vector2 .ONE
12
12
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
+
13
17
## Whether or not to automatically get the current camera
14
18
## every frame, could be beneifical to keep this off in certain
15
19
## circumstances, but is on by default for maximum performance.
16
20
@export var ignore_camera_changes : bool = true
17
21
18
22
## Internal variable used to track the current camera.
19
- var camera : Camera2D
23
+ var _camera : Camera2D
24
+ var _offset : Vector2 = Vector2 .ZERO
20
25
21
26
22
27
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
24
32
25
33
26
34
func _process (delta : float ) -> void :
27
35
if not ignore_camera_changes :
28
- camera = get_viewport ().get_camera_2d ()
36
+ _camera = get_viewport ().get_camera_2d ()
29
37
30
- if camera == null :
38
+ if _camera == null :
31
39
position = Vector2 .ZERO
32
40
return
33
41
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 )
Original file line number Diff line number Diff line change 3
3
name =" ParallaxNode"
4
4
description =" Alternative new node to the built-in ParallaxBackground & ParallaxLayer system, one that is simpler and is not affected by the camera's zoom."
5
5
author =" Midnight"
6
- version =" 0.0.2 "
6
+ version =" 0.0.3 "
7
7
script =" plugin.gd"
You can’t perform that action at this time.
0 commit comments