今天跟着教程调试某2D界面,发现人物绘图总和给定的position存在偏差,并且移动不按照现有的格子一格一格的移动.
最后通过断点确定了不是TileMap.Tileset.TileSize的问题.而是TileMap.Scale的问题,不知道是误操作还是默认的设置,总之这里的Scale不是(1,1).找到TileMap中Transform->Scale设置改回1,1就行了
一个借用SimpleTex解决在线Tex文档识别的方案
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
今天跟着教程调试某2D界面,发现人物绘图总和给定的position存在偏差,并且移动不按照现有的格子一格一格的移动.
最后通过断点确定了不是TileMap.Tileset.TileSize的问题.而是TileMap.Scale的问题,不知道是误操作还是默认的设置,总之这里的Scale不是(1,1).找到TileMap中Transform->Scale设置改回1,1就行了
前言:笔者是第一次使用godot,c#的一些高级特性也不是很精通.今天在跟着b站上视频教程时遇到了奇怪的问题,具体报错如下
xxxxxxxxxx
E 0:00:00:0426 object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void*, object): System.InvalidCastException: Unable to cast object of type 'Godot.Node' to type 'Fsm'.
<C++ 错误> System.InvalidCastException
<C++ 源文件> :0 @ object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void*, object)
<栈追踪> :0 @ object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void*, object)
NodeExtensions.cs:47 @ T Godot.Node.GetNode<T>(Godot.NodePath)
Main.cs:10 @ void Main._Ready()
Node.cs:2137 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
Main_ScriptMethods.generated.cs:48 @ bool Main.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)
在这里我实现了Fsm类,并在一个Main.cs
文件中导入这个节点GetNode<Fsm>("%Fsm")
x
using Godot;
public partial class Main : Node
{
private Fsm _fsm;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_fsm = GetNode<Fsm>("%Fsm");
GD.Print(_fsm.GetType().Name);
_fsm.Initialize();
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
_fsm.Update();
}
}
将此行_fsm = GetNode<Fsm>("%Fsm");
注释并使用GetNode("%Fsm")
,发现返回值为Node,并且该Node实例没有任何属性.
windows的godot4.2没有对场景的自动保存,因此在为场景添加c#脚本后需要手动保存,否则即使创建了c#脚本文件,但是没有和场景进行绑定.
由此,在前面的代码中实际上节点Fsm是不在节点Main下的.
手动指定Script后恢复正常.