center camera on load

This commit is contained in:
Candygoblen123 2024-02-26 13:09:17 -05:00
parent fe0d76e370
commit f31a6ee0c2
No known key found for this signature in database
GPG Key ID: 577DA64EBEF10385
5 changed files with 28 additions and 5 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@
export_presets.cfg
/AuthKey_VSYTQ75GZQ.p8
*.dds

View File

@ -1,5 +1,4 @@
extends Camera2D
class_name PanningCamera2D
@export var MIN_ZOOM: float = 0.5
@export var MAX_ZOOM: float = 3.0

12
main.gd Normal file
View File

@ -0,0 +1,12 @@
extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready():
var center = $Field.to_global($Field.tiles[$Field.tiles.size() / 2].position)
$Camera2D.position = center
$Camera2D.reset_pos = center
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass

View File

@ -1,14 +1,20 @@
[gd_scene load_steps=3 format=3 uid="uid://djirenq1psstj"]
[gd_scene load_steps=4 format=3 uid="uid://djirenq1psstj"]
[ext_resource type="Script" path="res://main.gd" id="1_2dcib"]
[ext_resource type="Script" path="res://PanningCamera/PanningCamera2D.gd" id="1_vtapg"]
[ext_resource type="PackedScene" uid="uid://qipfodwbk1gf" path="res://Field/field.tscn" id="1_y0qkv"]
[node name="Main" type="Node2D"]
script = ExtResource("1_2dcib")
metadata/_edit_group_ = true
[node name="Camera2D" type="Camera2D" parent="."]
limit_left = -5000
limit_top = -2000
limit_right = 5000
limit_bottom = 4000
editor_draw_limits = true
script = ExtResource("1_vtapg")
MIN_ZOOM = null
MAX_ZOOM = null
ZOOM_RATE = 5.0
[node name="Field" parent="." instance=ExtResource("1_y0qkv")]

View File

@ -15,13 +15,18 @@ run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.2", "GL Compatibility")
config/icon="res://icon.svg"
[debug]
gdscript/warnings/integer_division=0
[display]
window/size/viewport_width=1920
window/size/viewport_height=1080
window/vsync/vsync_mode=0
[rendering]
renderer/rendering_method="gl_compatibility"
renderer/rendering_method="mobile"
renderer/rendering_method.mobile="gl_compatibility"
textures/vram_compression/import_etc2_astc=true