首页 > 编程问答 >Godot:在页面间导航时出错;

Godot:在页面间导航时出错;

时间:2024-06-04 15:46:48浏览次数:12  
标签:godot godot4

我的代码有问题。

在此输入图片描述

所有按钮都可以点击。但是当进入排行榜时。

然后按下退出按钮。

所有按钮都无法使用,并且什么也做不了。 以下是错误信息。

_parse_ext_resource: res://scenes/main_menu.tscn:16 - 解析错误:[ext_resource] 在 res://script/main_menu.gd 引用了不存在的资源

set_path:从路径 'res://scenes/main_menu.tscn' 加载另一个资源(可能包含循环资源)

more

上述错误信息的屏幕截图

下面是主菜单的代码:

class_name MainMenu
    
扩展控件
    
@onready var play_button = $MarginContainer/HBoxContainer/VBoxContainer/Play_Buttom as Button
@onready var exit_button = $MarginContainer/HBoxContainer/VBoxContainer/Exit_Button as Button
@onready var leaderboar_button = $MarginContainer/HBoxContainer/VBoxContainer/Leaderboar_Button as Button
@onready var start_level = preload("res://scenes/game.tscn")
@onready var start_mainmenu = preload("res://scenes/leader_board.tscn")
    
func _ready():
    play_button.button_down.connect(on_play_pressed)
    exit_button.button_down.connect(on_exit_pressed)
    leaderboar_button.button_down.connect(on_leaderboard_pressed)

func on_play_pressed() -> void:
    get_tree().change_scene_to_packed(start_level)

func on_exit_pressed() -> void:
    get_tree().quit()

func on_leaderboard_pressed() -> void:
    get_tree().change_scene_to_packed(start_mainmenu)

下面是排行榜的代码:

 扩展控件
    
@onready var exit_button = $MarginContainer/HBoxContainer/VBoxContainer/Exit_Button
@onready var main_menu = preload("res://scenes/main_menu.tscn")
    
# 当节点首次进入场景树时调用。
func _ready(
    exit_button.button_down.connect(open_main_menu)

func open_main_menu():
    get_tree().change_scene_to_packed(main_menu)

我已经尝试了所有方法,但我不知道如何解决这个问题。


The problem lies in your leaderboard scene script. You are attempting to load the main_menu.tscn scene in the open_main_menu function, but you have a typo in the resource path.

Here's the problematic line:

@onready var main_menu = preload("res://scenes/main_menu.tscn") 

The issue is that your Main Menu scene is saved as Main Menu.tscn (with capital letters), but you are referencing it as main_menu.tscn (lowercase).

Godot's file system is case-sensitive, so it treats these as two different files. Since it cannot find a file named main_menu.tscn , it throws the "Parse Error: [ext_resource]" you see.

Solution:

Correct the resource path in your leaderboard scene script to match the actual filename:

@onready var main_menu = preload("res://scenes/Main Menu.tscn") 

Make sure this path accurately reflects the location of your main menu scene file in your Godot project. Once you've made this change, save your script and try running the game again. The buttons should work correctly after returning from the leaderboard.

标签:godot,godot4
From: 78484727

相关文章

  • 视差背景,GODOT游戏引擎学习笔记(五)
    背景图片资源今天周六玩了一天,现在晚上来更新一下帖子。前面几节我们学习了创建一个人物精灵节点使其移动。这节我们来学习创建背景。会用到三个图片文件。我已经上传到csdn了,链接如下:https://download.csdn.net/download/weixin_66990397/89356894?spm=1001.2014.3001.5501......
  • 开坑开坑,GODOT游戏引擎学习笔记(一)
    前言         本人重度游戏玩家,计科专业学生,玩了许多游戏已经逐渐电子羊尾,于是打算学习几个游戏引擎,一个方面是爱好,另一方面也是多掌握点技术。先打算从2D游戏开始学,目前引擎确定为GODOT,一个开源且适合新手的引擎。后续学习unity和虚幻等引擎也会继续更新,同时也会开......
  • Godot Breakeys Godot Beginner Tutorial 游戏开发笔记
    目录前言资源下载添加人物节点运动状态机移动平台单向穿过奇怪的BugArea2DBodyEntered死亡区域全局类多线程安全TileMap处理TileMap分层前言这次来学习一下youtube的传奇Unity博主,Breakeys的Godot新手教程。Breakeys是从15岁左右就开始用unity做游戏并在youtube上面发布视频了。......
  • 如何编译Godot(Godot & Godot with C#)
    要在Windows下编译Godot,需要以下环境:VisualStudioCommunity:使用最新版本。MinGW-w64:可以替代VisualStudio。请务必将其安装/配置为使用posix线程模型。使用MinGW编译主分支时,需要GCC9或更高版本。Python3.6+:确保在安装程序中启用将Python添加到环境变量......
  • 【转载】Godot-GDExtension C++ 环境搭建 (Docker+MinGW/跨平台)
    本文原链接见 Godot-GDExtensionC++环境搭建(Docker+MinGW/跨平台)|Convexwf'sKirakiraBlog。Godot在4.X之后推出了GDExtension,通过第三方绑定扩展功能,目前官方支持的语言只有C++。通过使用GDExtensionC++编写扩展插件,可以作为库文件在Godot中交互使用。GDExten......
  • Godot.NET C#IOC重构(11):攻击与死亡
    目录前言带上伤害HitboxHurtbox实现效果渐变淡出添加受攻击效果Hurtbox完善Enemy状态机结果剩下的都是逻辑完善的部分了,后面的我就跳过了。前言这次来深刻了解一下Godot中的伤害计算带上伤害我们将之前的Hitbox和HurtBox进行了一下简单的修改HitboxusingGodot;usingSyste......
  • Unity导出场景并导入Godot
    使用FBXExporter导出场景FBX创建ExportScene.cs导出场景OBJ(目的是创建碰撞体),代码:点击查看代码/******************************************//**//*Copyright(c)2018monitor1394*//*https://github.com/monito......
  • Godot.NET C#IOC重构(9-10):三连击,攻击框
    目录前言AnimationPlayer和AnimatedSprite2D将导出属性添加到关键帧里面。状态机构建核心代码完整代码实现效果碰撞框和受攻击框全局类HitBox:攻击框HurtBox:受击框实现效果添加Player攻击总结前言这篇博客来深入讲解一下Godot中的AnimationPlayerAnimationPlayer和AnimatedSpr......
  • Godot的游戏开发思考(无代码)
    目录前言GDScriptorC#?C#IOC开发代码和引擎的平衡Godot如何学习多而精炼的小Demo后面的学习的方向Ai绘画和Ai声音的学习前言我断断续续学了快半年的Godot了吧,从去年的Unity事件发生之后开始接触,然后断断续续学到了现在,这里就简单讲讲我对Godot的看法GDScriptorC#?GDScript......
  • Godot中设置Sprite2D节点透明度
    Godot中设置Sprite2D节点透明度该方法可以用于所有CanvasItem​类及其子类···#假设在`CancasItem`节点自身脚本中执行#设置范围0~1##设置自己及子节点modulate.a=0.5##仅设置自己节点的透明度self_modulate.a=0.5#设置范围(0~255)8bit##设置自己及子节点mod......