commit 1dbc43df656ae8120201d2fd05b0c76b951b8138
parent d11218d78b67857b9f6e362dc1891082ec150a33
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date: Thu, 30 Sep 2021 14:44:38 +0300
Add notes and background display code.
Diffstat:
4 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/Camera.gd b/Camera.gd
@@ -17,9 +17,11 @@ extends Camera
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
+onready var player: KinematicBody = get_parent().get_node("Player")
+onready var mesh_instance: MeshInstance = $MeshInstance
+
var offset
-onready var player: KinematicBody = get_parent().get_node("Player")
func _ready() -> void:
@@ -30,3 +32,17 @@ func _process(delta: float) -> void:
translation.x = player.translation.x + offset.x
# translation.y = player.translation.y + offset.y
translation.z = player.translation.z + offset.z
+
+# display_background()
+
+
+func display_background() -> void:
+ # TODO: Crop excess background image?
+
+ var viewport_size: Vector2 = get_viewport().size
+ var mesh_distance_from_camera: float = abs(mesh_instance.translation.z)
+ var worldspace_top_left: Vector3 = project_position(Vector2(0, 0), mesh_distance_from_camera)
+ var worldspace_bottom_right: Vector3 = project_position(viewport_size, mesh_distance_from_camera)
+ var local_top_left: Vector3 = to_local(worldspace_top_left)
+ var local_bottom_right: Vector3 = to_local(worldspace_bottom_right)
+ mesh_instance.mesh.size = Vector2(abs(local_top_left.x-local_bottom_right.x), abs(local_top_left.y - local_bottom_right.y))
diff --git a/Level1.tscn b/Level1.tscn
@@ -10,6 +10,7 @@ script = ExtResource( 4 )
[node name="Camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 0.964893, 0.262644, 0, -0.262644, 0.964893, 0, 0.937895, 0.953137 )
+far = 726.3
script = ExtResource( 1 )
[node name="Player" parent="." instance=ExtResource( 2 )]
@@ -18,6 +19,6 @@ script = ExtResource( 1 )
[node name="Boxes" type="Spatial" parent="."]
[connection signal="off_the_deep_end" from="Player" to="." method="_on_Player_off_the_deep_end"]
-[connection signal="reached_goal" from="Player" to="HUD" method="_on_Player_reached_goal"]
[connection signal="reached_goal" from="Player" to="." method="_on_Player_reached_goal"]
+[connection signal="reached_goal" from="Player" to="HUD" method="_on_Player_reached_goal"]
[connection signal="speed_changed" from="Player" to="HUD" method="_on_Player_speed_changed"]
diff --git a/LevelSelection.tscn b/LevelSelection.tscn
@@ -80,6 +80,3 @@ size_flags_vertical = 3
text = "Space Station (putative)"
[connection signal="item_selected" from="HBoxContainer/VBoxContainer/ItemList" to="." method="_on_ItemList_item_selected"]
[connection signal="pressed" from="HBoxContainer/VBoxContainer/Button" to="." method="_on_Button_pressed"]
-[connection signal="pressed" from="HBoxContainer/VBoxContainer/Button2" to="." method="_on_Button_pressed"]
-[connection signal="pressed" from="HBoxContainer/VBoxContainer/Button3" to="." method="_on_Button_pressed"]
-[connection signal="pressed" from="HBoxContainer/VBoxContainer/Button4" to="." method="_on_Button_pressed"]
diff --git a/notes.md b/notes.md
@@ -0,0 +1,9 @@
+## Display background image by:
+
+1. Add MeshInstance to camera node.
+2. Set MeshInstance's Mesh property to PlaneMesh.
+3. Load image file:
+ MeshInstance -> Mesh -> PlaneMesh -> Material -> Albedo -> Load (in the popup menu).
+4. Change rotation of the MeshInstance to be directly in front of the Camera.
+5. There is `display_background()` code in the Camera.gd script to set the distance.
+6. Change Camera's "far", most distant rendered thing, property to fit in the MeshInstance.