1 Star 0 Fork 0

kevinlights/rimworldripoff

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CameraController.gd 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
Jake Wilkinson 提交于 2024-05-04 21:47 +08:00 . video 3 - camera controller
extends Camera2D
@export var zoomSpeed : float = 10;
var zoomTarget :Vector2
var dragStartMousePos = Vector2.ZERO
var dragStartCameraPos = Vector2.ZERO
var isDragging : bool = false
# Called when the node enters the scene tree for the first time.
func _ready():
zoomTarget = zoom
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
Zoom(delta)
SimplePan(delta)
ClickAndDrag()
func Zoom(delta):
if Input.is_action_just_pressed("camera_zoom_in"):
zoomTarget *= 1.1
if Input.is_action_just_pressed("camera_zoom_out"):
zoomTarget *= 0.9
zoom = zoom.slerp(zoomTarget, zoomSpeed * delta)
func SimplePan(delta):
var moveAmount = Vector2.ZERO
if Input.is_action_pressed("camera_move_right"):
moveAmount.x += 1
if Input.is_action_pressed("camera_move_left"):
moveAmount.x -= 1
if Input.is_action_pressed("camera_move_up"):
moveAmount.y -= 1
if Input.is_action_pressed("camera_move_down"):
moveAmount.y += 1
moveAmount = moveAmount.normalized()
position += moveAmount * delta * 1000 * (1/zoom.x)
func ClickAndDrag():
if !isDragging and Input.is_action_just_pressed("camera_pan"):
dragStartMousePos = get_viewport().get_mouse_position()
dragStartCameraPos = position
isDragging = true
if isDragging and Input.is_action_just_released("camera_pan"):
isDragging = false
if isDragging:
var moveVector = get_viewport().get_mouse_position() - dragStartMousePos
position = dragStartCameraPos - moveVector * 1/zoom.x
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kevinlights/rimworldripoff.git
git@gitee.com:kevinlights/rimworldripoff.git
kevinlights
rimworldripoff
rimworldripoff
master

搜索帮助