Title image
Venusの自留地

Godot复刻BongoCat


1. 简介

参考 https://github.com/Yanxiyimengya/GodotBongoCat 项目做的桌宠,Godot本身不支持全局输入监听,这个项目用C#来写脚本去调用第三方库来实现,我用了 https://github.com/aliarcanakgun/gd-global-input 这个项目的GDExtension实现全gdscript实现全局输入监听。

关于什么是GDExtension你可以在这里查看。

2. 实现

项目本身没什么好说的,全部代码可以在我的仓库查看,除了基础的监听输入切换动作外还复刻原版的鼠标拖拽、鼠标穿透和托盘化。

主体代码:

extends Control

enum CatState{BODY_POSE,ARM_POSE}

var current_state=CatState.BODY_POSE
@export var catbody:TextureRect
@export var catarm:TextureRect
@export var body_normal:Texture2D
@export var body_pressed:Texture2D
@export var arm_normal:Texture2D
@export var arm_pressed:Texture2D

func _process(delta: float) -> void:
	if GlobalInput.is_global_input_just_pressed("key"):
		set_cat_pressed(true)
	elif GlobalInput.is_global_input_just_released("key"):
		set_cat_pressed(false)

func set_cat_pressed(pressed:bool):
	if pressed:
		match current_state:
			CatState.BODY_POSE:
				catbody.texture=body_pressed
				catarm.texture=arm_normal
				current_state=CatState.ARM_POSE
			CatState.ARM_POSE:
				catbody.texture=body_normal
				catarm.texture=arm_pressed
				current_state=CatState.BODY_POSE
	else:
		catbody.texture=body_normal
		catarm.texture=arm_normal


本文总阅读量:




:D 获取中...


© - Venus - 2023 - 2026 - Powered by Hexo Theme Quark


加载中... 我正在使用
电量: --%
设备: Redmi Note9P