godot-start/script/demo13_camera/switch_camera.gd

56 lines
1.2 KiB
GDScript
Raw Normal View History

2021-10-07 01:31:11 +00:00
extends Node2D
2022-01-22 06:05:17 +00:00
const StringUtils = preload("res://zfoo/util/StringUtils.gd")
2021-10-07 01:31:11 +00:00
var camera1: Camera2D
var camera2: Camera2D
var camera3: Camera2D
var camera4: Camera2D
var timerCounter = 0
func _ready() -> void:
camera1 = get_node("Camera2D1")
camera2 = get_node("Camera2D2")
camera3 = get_node("Camera2D3")
camera4 = get_node("Camera2D4")
func _physics_process(delta: float) -> void:
2022-01-22 06:05:17 +00:00
timerCounter += 1
if(timerCounter == 100):
2021-10-07 01:31:11 +00:00
switchCamera1()
2022-01-22 06:05:17 +00:00
if(timerCounter == 200):
2021-10-07 01:31:11 +00:00
switchCamera2()
2022-01-22 06:05:17 +00:00
if(timerCounter == 300):
2021-10-07 01:31:11 +00:00
switchCamera3()
2022-01-22 06:05:17 +00:00
if(timerCounter == 400):
2021-10-07 01:31:11 +00:00
switchCamera4()
timerCounter = 0
func switchCamera1() -> void:
camera1.current = true;
2022-01-22 06:05:17 +00:00
print("camera1---------------------------")
postionTest()
2021-10-07 01:31:11 +00:00
func switchCamera2() -> void:
camera2.current = true;
2022-01-22 06:05:17 +00:00
print("camera2---------------------------")
postionTest()
2021-10-07 01:31:11 +00:00
func switchCamera3() -> void:
camera3.current = true;
2022-01-22 06:05:17 +00:00
print("camera3---------------------------")
postionTest()
2021-10-07 01:31:11 +00:00
func switchCamera4() -> void:
camera4.current = true;
2022-01-22 06:05:17 +00:00
print("camera4---------------------------")
postionTest()
func postionTest():
print(StringUtils.format("全局坐标[{}]", [$icon.global_position]))
print(StringUtils.format("屏幕坐标[{}]", [$icon.get_global_transform_with_canvas().get_origin()]))