为什么 Camera2D(或视口)在 Godot 4 中不移动?

问题描述 投票:0回答:1

我创建了游戏的主关卡场景,它一直在工作,直到我完成了标题场景和过渡。我有一个带有简单脚本的 Camera2D 节点:

extends Camera2D
@export var desCentrar := 650
@export var player : CharacterBody2D
func _process(delta):
position.x = player.position.x + desCentrar

print(position.x)

这是相机设置:

相机设置

非常感谢任何指导!!!

打印位置时,显示相机在移动,但在视口中却没有移动。我想可能是我在主标题屏幕和过渡中工作时更改了显示项目设置中的某些设置。我检查了项目设置,但无法解决问题。 编辑: 好的,我尝试更改窗口项目设置,将分辨率和比例减半。完成此操作并从标题屏幕开始玩游戏时,主关卡开始,摄像机会跳转然后开始移动(有时)。我看到跳转正在视口中获取初始视图并跳转到相机视图。就像相机有几秒钟没有加载一样。 有没有办法预加载相机节点?

camera 2d game-development godot godot4
1个回答
0
投票

所以,我解决了这个问题。当过渡场景和主场景重叠时,场景中的摄像机会产生问题。当转场场景在透明部分显示主场景时,正在使用转场场景相机,并忽略主场景相机。当删除过渡场景 (

queue_free()
) 时,摄像机会跳转到主场景中摄像机的位置。 我通过在过渡场景中禁用相机来解决这个问题,并且至少在我需要更改分辨率设置并需要相机重新构建过渡之前,问题已经“解决”。

我仍然不知道为什么它在播放活动场景中执行时会影响主场景摄像机。不过也解决了。

我不知道这对@ZapTap是否有用,但是接下来是txt格式的主场景(我不知道如何使用这些数据,我是Godot新手:

[gd_scene load_steps=23 format=3 uid="uid://bsf2o7tbx7jf4"]

[ext_resource type="PackedScene" uid="uid://ctpj7vutf8x8t" path="res://Player/Player.tscn" id="1_ucvfk"]
[ext_resource type="PackedScene" uid="uid://celueydse0ha7" path="res://Assets/platform_big.tscn" id="2_km684"]
[ext_resource type="Script" path="res://Scripts/Camera2D.gd" id="4_1eqss"]
[ext_resource type="PackedScene" uid="uid://bvcblmp3arcru" path="res://Assets/platform_small.tscn" id="4_s304j"]
[ext_resource type="PackedScene" uid="uid://c5lm07yh2k1od" path="res://Assets/BackGround.tscn" id="5_f58ky"]
[ext_resource type="Script" path="res://Scripts/Eraser.gd" id="5_mtntl"]
[ext_resource type="Script" path="res://Scripts/DieZone.gd" id="7_8lb55"]
[ext_resource type="PackedScene" uid="uid://can3i0w42b5j3" path="res://Assets/ItemGenerator.tscn" id="7_8tphp"]
[ext_resource type="PackedScene" uid="uid://c6flqyyver72a" path="res://Assets/generador.tscn" id="8_0jbxy"]
[ext_resource type="PackedScene" uid="uid://e6me4r5mvkna" path="res://Assets/sparks_up.tscn" id="9_kegdm"]
[ext_resource type="PackedScene" uid="uid://e0jucg1w6dji" path="res://Assets/puntaje.tscn" id="9_qlkeu"]
[ext_resource type="Script" path="res://Scripts/sparks_up.gd" id="10_yihnu"]
[ext_resource type="PackedScene" uid="uid://dbpqyfxsyfy72" path="res://Assets/Items/Beef.tscn" id="13_xd71t"]
[ext_resource type="PackedScene" uid="uid://weueemnh2v05" path="res://Assets/Items/Celula.tscn" id="14_kf4ss"]
[ext_resource type="PackedScene" uid="uid://5c6li8r0f757" path="res://Assets/Items/Leg.tscn" id="15_r6vdc"]
[ext_resource type="PackedScene" uid="uid://bvcvsjon3p1ji" path="res://Assets/Items/Lengua.tscn" id="16_iye50"]
[ext_resource type="Script" path="res://Scripts/gameTimer.gd" id="17_kjjac"]
[ext_resource type="PackedScene" uid="uid://cgiqvhojh0520" path="res://Player/Player_Musc.tscn" id="18_kdfe2"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_slslj"]
size = Vector2(2151, 165.5)

[sub_resource type="RectangleShape2D" id="RectangleShape2D_fe4jy"]
size = Vector2(416.512, 20)

[sub_resource type="RectangleShape2D" id="RectangleShape2D_ay8dg"]
size = Vector2(229.466, 20)

[sub_resource type="RectangleShape2D" id="RectangleShape2D_c845b"]
size = Vector2(227, 2912)

[node name="MainLevel" type="Node2D"]

[node name="Platform_big" parent="." instance=ExtResource("2_km684")]
position = Vector2(1158, 989)
scale = Vector2(1.315, 1.315)

[node name="platform_small" parent="." instance=ExtResource("4_s304j")]
position = Vector2(2737, 962)
scale = Vector2(1.315, 1.315)

[node name="platform_small2" parent="." instance=ExtResource("4_s304j")]
position = Vector2(3770, 962)
scale = Vector2(1.315, 1.315)

[node name="platform_small3" parent="." instance=ExtResource("4_s304j")]
position = Vector2(4796, 962)
scale = Vector2(1.315, 1.315)

[node name="ParallaxBackground" parent="." instance=ExtResource("5_f58ky")]

[node name="Player" parent="." instance=ExtResource("1_ucvfk")]
z_index = 2
z_as_relative = false
y_sort_enabled = true
position = Vector2(441, 796)
scale = Vector2(0.376, 0.376)
SPEED = 400.0
gravity = 3500

[node name="Beef" parent="." instance=ExtResource("13_xd71t")]
position = Vector2(865, 796)

[node name="Celula" parent="." instance=ExtResource("14_kf4ss")]
position = Vector2(1060, 823)

[node name="Leg" parent="." instance=ExtResource("15_r6vdc")]
position = Vector2(1264, 823)

[node name="Lengua" parent="." instance=ExtResource("16_iye50")]
position = Vector2(1596, 819)

[node name="gameTimer" type="Timer" parent="."]
unique_name_in_owner = true
one_shot = true
script = ExtResource("17_kjjac")

[node name="Player2" parent="." instance=ExtResource("18_kdfe2")]
visible = false
position = Vector2(611, 801)
scale = Vector2(0.395, 0.395)

[node name="Camera2D" type="Camera2D" parent="." node_paths=PackedStringArray("player")]
show_behind_parent = true
top_level = true
z_index = 3
position = Vector2(960, 540)
scale = Vector2(0.999998, 0.999998)
script = ExtResource("4_1eqss")
player = NodePath("../Player")

[node name="Limits" type="Node2D" parent="Camera2D"]
position = Vector2(-961, -541)

[node name="LimitUp" type="StaticBody2D" parent="Camera2D/Limits"]
position = Vector2(36, -306)

[node name="CollisionShape2D" type="CollisionShape2D" parent="Camera2D/Limits/LimitUp"]
position = Vector2(995, -158)
shape = SubResource("RectangleShape2D_slslj")
metadata/_edit_lock_ = true

[node name="DieZone" type="Area2D" parent="Camera2D/Limits"]
position = Vector2(970, 1242)
script = ExtResource("7_8lb55")
metadata/_edit_lock_ = true

[node name="CollisionShape2D" type="CollisionShape2D" parent="Camera2D/Limits/DieZone"]
position = Vector2(300, 0)
scale = Vector2(7.025, 7.025)
shape = SubResource("RectangleShape2D_fe4jy")
metadata/_edit_lock_ = true

[node name="DieZone2" type="Area2D" parent="Camera2D/Limits"]
position = Vector2(-102, 0)
script = ExtResource("7_8lb55")
metadata/_edit_lock_ = true

[node name="CollisionShape2D" type="CollisionShape2D" parent="Camera2D/Limits/DieZone2"]
position = Vector2(-6.00109, 507)
rotation = 1.57079
scale = Vector2(7.025, 7.025)
shape = SubResource("RectangleShape2D_ay8dg")
metadata/_edit_lock_ = true

[node name="Eraser" type="Area2D" parent="Camera2D/Limits"]
position = Vector2(-2203, 8)
script = ExtResource("5_mtntl")
metadata/_edit_lock_ = true

[node name="CollisionShape2D" type="CollisionShape2D" parent="Camera2D/Limits/Eraser"]
position = Vector2(27, 465)
shape = SubResource("RectangleShape2D_c845b")
metadata/_edit_lock_ = true

[node name="PlatGenerador" parent="Camera2D" instance=ExtResource("8_0jbxy")]
position = Vector2(3677, -249)
timeMax = 5.0

[node name="PlatGenerador2" parent="Camera2D" instance=ExtResource("8_0jbxy")]
position = Vector2(3244, 94)
timeMax = 10.0
timeMin = 3.0

[node name="PlatGenerador3" parent="Camera2D" instance=ExtResource("8_0jbxy")]
position = Vector2(2891, 418)
timeMax = 6.0
timeMin = 2.0

[node name="ItemGenerator" parent="Camera2D" instance=ExtResource("7_8tphp")]
position = Vector2(3813, -370)
timeMax = 10.0
timeMin = 5.0

[node name="ItemGenerator2" parent="Camera2D" instance=ExtResource("7_8tphp")]
position = Vector2(3441, -62)
timeMax = 3.0
timeMin = 5.0

[node name="ItemGenerator3" parent="Camera2D" instance=ExtResource("7_8tphp")]
position = Vector2(3017, 270)
timeMax = 2.0
timeMin = 3.0

[node name="Porcentaje" parent="Camera2D" instance=ExtResource("9_qlkeu")]
offset_left = 819.0
offset_top = -436.0
offset_right = 859.0
offset_bottom = -379.0

[node name="SparksUp" parent="Camera2D" instance=ExtResource("9_kegdm")]
position = Vector2(954, 434)
emitting = false
script = ExtResource("10_yihnu")

[node name="MarkPosScore" type="Marker2D" parent="Camera2D"]
position = Vector2(1337, -401)

[connection signal="comenzo" from="Player" to="Player" method="_on_comenzo"]
[connection signal="comenzo" from="Player" to="Camera2D/PlatGenerador" method="_on_player_comenzo"]
[connection signal="comenzo" from="Player" to="Camera2D/PlatGenerador2" method="_on_player_comenzo"]
[connection signal="comenzo" from="Player" to="Camera2D/PlatGenerador3" method="_on_player_comenzo"]
[connection signal="comenzo" from="Player" to="Camera2D/ItemGenerator" method="_on_player_comenzo"]
[connection signal="comenzo" from="Player" to="Camera2D/ItemGenerator2" method="_on_player_comenzo"]
[connection signal="comenzo" from="Player" to="Camera2D/ItemGenerator3" method="_on_player_comenzo"]
[connection signal="timeout" from="gameTimer" to="Player" method="_on_game_timer_timeout"]
[connection signal="body_entered" from="Camera2D/Limits/DieZone" to="Camera2D/Limits/DieZone" method="_on_body_entered"]
[connection signal="body_entered" from="Camera2D/Limits/DieZone2" to="Camera2D/Limits/DieZone2" method="_on_body_entered"]
[connection signal="body_entered" from="Camera2D/Limits/Eraser" to="Camera2D/Limits/Eraser" method="_on_body_entered"]
© www.soinside.com 2019 - 2024. All rights reserved.