Posts

Showing posts with the label godot

Stacked Sprites in Godot

Image
 

Godot安卓调试与导出

 安装Android SDK:(command line tools) Exporting for Android — Godot Engine (stable) documentation in English Android SDK - Command line tools Installation (Detailed) - YouTube 实机调试: 开启开发者模式(系统版本号介面连续点击) 连接USB 连接模式设置为传送文件 开启USB调试模式(设置内) 安卓10以上显示底部菜单:导出时取消immersive mode(沉浸模式) How do I make Android 10 navigation bar visible? - Godot Engine - Q&A 如果仍未起作用:安装自定义导出模板 Custom builds for Android — Godot Engine (stable) documentation in English 并修改 "android/build/res/values/themes.xml" 文件内的 <style name="GodotAppMainTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen"/> 改为 <style name="GodotAppMainTheme" parent="@android:style/Theme.Black.NoTitleBar"/> Immersive mode OFF for Android still doesn't show the status bar · Issue #48811 · godotengine/godot (github.com)

Godot UI

Button按钮 set_pressed_no_signal(仅toggle mode下有效),设置button状态且不触发信号

Godot信号

 信号可以在代码中声明 signal node_ready signal weapon_shooted(damage) 第二种带有变量的声明除了可以在编辑器中看到之外,我没有发现有什么不同,信号发射时默认不带参数。 信号发射时,链接到的函数参数如果比信号参数少,则不能触发。但是函数参数更多且未传入的参数有默认值则可以触发 emit_signal("test_signal", "hello") func _ _on_test_signal_triggered(a, b = " world"):     print(a + b) 自带参数和bind的参数不同,bind参数自动发送,优先度在自带参数之后 注意bind的参数在绑定之后就不可更改了,即使参数已经发生了变化,仍旧发送最初的数值 自带参数可以用一个信号达成不同效果 bind可以同时绑定多个参数。 func _ready():      self.connect("test_signal", self, "_on_test_signal_triggered", ["default bind var"])      emit_signal("test_signal", "button pressed") func _on_test_signal_triggered(var1, var2): print(str(var1) + str(var2)) 输出button presseddefault bind var

从blender导出模型到Godot

Image
1) 导出格式为 gltf packed 2) shape keys 和 modifiers可能不能同时使用(冲突) 3) check modifiers if you have used them and turn off shape keys during export. 4) Uncheck keep materials in godot on consecutive reimports. Click on the button until it reimports properly or restart godot. 5) materials can be imported on per node level or model level

godot editor plugin入门

Image
新建插件 主要方法 ● bool handles(object: Object) virtual 如果插件编辑了一个特定类型的对象(资源或节点),就执行这个函数。 如果返回true,则编辑器请求时将调用edit()和make_visible()函数。 如果您已经声明了方法forward_canvas_gui_input()和forward_spatial_gui_input(),它们也将被调用。 使用plugin更改节点的export var后,可以手动调用edited_node.property_list_changed_notify()方法来更新编辑器的查看器。 生成节点 使用plugin生成节点并添加到当前编辑的场景中,需要将新node的owner设为get_tree().edited_scene_root或其他为packedscenen的父节点(owner即是其跟随保存的packedscene节点)。即否则不能保存到文件中,且在场景树查看器中无法看到。(但仍然可以在canvas editor或spatial editor中查看,但是不能选中,并且不能保存到文件内)

Godot 资源管理

Owner与PackedScene  owner 节点的所有者。 一个节点可以有任何其他节点作为owner(只要它是树中有效的父节点、以及父节点的上层)。 当保存一个节点(使用PackedScene)时,它拥有的所有节点都会被保存。 这允许创建复杂的SceneTrees,包括实例化和子实例化。 set_owner要在add_child()后使用 注意pack方法并不会保存子节点拥有的节点,即owner效果不能向上传递。如果将节点owner设为非父级的packedScene,则此节点及其所有子节点均不能保存到packedscene   将当前节点保存为场景文件 var pack = PackedScene.new() pack.pack(self) ResourceSaver.save("res://SceneTree/TestPack.tscn", pack)

Godot Autoload

Autoload(singleton)必须是基础自node的script或者是packedscene func add_autoload(name, resource):     var node     if resource is Script:         node = resource.new()     elif resource is PackedScene:         node = resource.instance()     else:         return     node.name = name     get_tree().get_root().add_child(node)     # node now exists at $/root/DialogueSystem

godot _set() _get()方法

What are the differences in using set and get vs just setting the variables straight - Godot Engine - Q&A GDScript's  _get() and  _set(): How and When to Use Them (jwestman.net) set(), get(), _set(), _get() 获取或更改变量 例如如果health变量并未声明,则 var new_health = health 语句会出错 而使用get("health")则会返回null。set()同理设置并不存在的属性则什么都不会发生 _get()和_set()则是覆盖方法,类似于setget,只不过写在一起,处理某些情况更为方便。比如更新player的属性: var health var energy var power func _set(property, value):     emit_signal("player_status_updated", {property:value}) _set(), _get()默认执行默认的数值设置和获取代码,所以 func _set(property, value):     print("do nothing!) 也是可以正常运行的。_set,_get内的代码只有在使用set(),get()时才会触发

Godot get_property_list

enum PropertyHint {     PROPERTY_HINT_NONE, ///< no hint provided.     PROPERTY_HINT_RANGE, ///< hint_text = "min,max,step,slider; //slider is optional"     PROPERTY_HINT_EXP_RANGE, ///< hint_text = "min,max,step", exponential edit     PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc"     PROPERTY_HINT_EXP_EASING, /// exponential easing function (Math::ease) use "attenuation" hint string to revert (flip h), "full" to also include in/out. (ie: "attenuation,inout")     PROPERTY_HINT_LENGTH, ///< hint_text= "length" (as integer)     PROPERTY_HINT_SPRITE_FRAME, // FIXME: Obsolete: drop whenever we can break compat. Keeping now for GDNative compat.     PROPERTY_HINT_KEY_ACCEL, ///< hint_text= "length" (as integer)     PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags)     PROPERTY_HINT_LAYERS_2D_RENDER,     PROPERTY_HINT_LAYERS_2D_PHYSIC...

godot export vars 列表

  List of export hints - Godot Engine - Q&A Godot exports hints If the exported value assigns a constant or constant expression, the type will be inferred and used in the editor.export var number = 5 Export can take a basic data type as an argument, which will be used in the editor.export(int) var number Export can also take a resource type to use as a hint.export(Texture) var character_face export(PackedScene) var scene_file There are many resource types that can be used this way, try e.g. the following to list them:export(Resource) var resource Integers and strings hint enumerated values. Editor will enumerate as 0, 1 and 2.export(int, "Warrior", "Magician", "Thief") var character_class Editor will enumerate with string names.export(String, "Rebecca", "Mary", "Leah") var character_name Named enum values Editor will enumerate as THING1, THING2, ANOTHER_THING.enum NamedEnum {THING_1, THING_2, ANOTHER_THING = -1} export (Na...

godot _set()和_get()

  GDScript's  _get() and  _set(): How and When to Use Them 27 December 2020 I recently found myself writing this monstrosity of a line of code in Godot Engine: var owner : = Client . db . get_subobject ( "players" ) . get_subobject ( str ( value . owner )) And immediately thought there must be a better way. It turns out, there is: the  _get ,  _set , and  _get_property_list  methods. They allow you to define properties of your GDScript object at runtime, not just at compile time, which is a very powerful technique when used appropriately. Now that code looks like this: var owner : = Client . db . players [ str ( value . owner )] Getters and setters, but for everything _get()  is a virtual method that acts sort of like the  get  half of  setget , but for any property that isn’t already defined by your class. You can do whatever you want in that function, and you return the value of the requested property (or  null  ...

Godot 纹理导入

  Importing images — Godot Engine (stable) documentation in English 由于在启用 sRGB 时纹理将修改其数据,这意味着在 2D 和 3D 中使用相同的纹理将使纹理在 2D 或 3D 中以不正确的颜色显示。 要解决此问题,请在文件系统上创建纹理的副本,并仅在其中一个副本上启用 sRGB。在 3D 模式下使用启用了 sRGB 的副本,在 2D 模式下禁用了 sRGB 的副本 。

Godot多线程

 Godot中线程可用来加载关卡,来防止UI阻塞。 线程和wait_to_finish()如何工作?- 戈多引擎 - 问答 (godotengine.org) var thread=Thread.new() func starting_function()      thread.start(self, "thread_function", func_param) func thread_function( func_param )      var r=do_your_stuff()      call_deferred("ending_function")       return r #this value will be passed to ending_function  func ending_function():       var result=thread.wait_to_finish() #result=r       do_stuff_with_result() 如果您不需要返回值,则执行相同操作的快速方法是调用thread.call_deferred("wait_to_finish")

Godot好玩好用的addon和demo合集

2D粒子碰撞:  danilw/Godot-particles-collision: particles with collision for Godot (github.com)

Godot节点NodePath

场景树中预解析的相对或绝对路径,用于 Node.get_node 和类似函数。它可以引用节点、节点中的资源或节点或资源的属性。例如,将引用名为"Sprite"的节点上纹理资源的大小属性,该节点是路径中其他命名节点的子节点。请注意,如果要获取资源,则必须以冒号结束路径,否则最后一个元素将用作属性名称。"Path2D/PathFollow2D/Sprite:texture:size" NodePath — Godot Engine (3.0) 英文文档

Godot UndoRedo

# First you create an action. UndoRedo.create_action("action name")  # Then you add your do and undo methods,  UndoRedo.add_do_method(Object that owns method, "do method name") UndoRedo.add_undo_method(Object that owns method, "undo method name")  # And/or if a property changes in the process you add do and undo properties for those too. UndoRedo.add_do_property(Object that own property, "property", new value) UndoRedo.add_undo_property(Object that own property, "property", old value) # Finally you commit the action. UndoRedo.commit_action()

godot多叉树遍历

Image
Tree traversal - Wikipedia Tree Traversals (Inorder, Preorder and Postorder) - GeeksforGeeks 遍历多叉树 - 简书 (jianshu.com) 广度优先 缺陷--pop_front()在大型数组中执行较慢 func traverse_breath_order(): var deque = [] var node = self deque.append(node) while deque.size() > 0: node = deque.pop_front() print(node.text) deque.append_array(node.get_children()) 输出结果 root A B A1 A2 A3 B1 B2 A11 A31 A32 深度优先 #数组遍历深度逆序 func traverse_preorder_inversed(): var deque = [] var node = self deque.append(node) while deque.size() > 0: node = deque.pop_back() print(node.text) deque.append_array(node.get_children()) 输出结果 root B B2 B1 A A3 A32 A31 A2 A1 A11 #递归遍历深度 func recurse_preorder(node): print(node.text) for i in node.get_children(): recurse_preorder(i) 输出结果 root B B2 B1 A A3 A32 A31 A2 A1 A11 #数组遍历深度 func traverse_preorder(): var deque = [] var node = self deque.append(node) while deque.size() > 0: node = deque.pop_back() print(node.text) var m = node.get_...

godot声音特效

Image
Audio streams — Godot Engine (stable) documentation in English 增幅(Amplify) 增幅改变信号的振幅. 使用时要小心. 把电平调得太高的话, 声音就会被削波, 这通常是不可取的. 带限和带通(BandLimit and BandPass) 它们是共振滤波器, 在 截断 (Cutoff)点附近阻断频率. 带通滤波器可以用来模拟旧电话线路或扩音器传出的声音. 调节带通滤波器的频率, 可以模拟吉他哇音(wah-wah)踏板的声音, 想想吉米·亨德里克斯在 Voodoo Child (Slight Return) 中使用的吉他吧. Capture(捕获) 其所在的音频总线的音频帧复制到内部缓冲区中。 这可以用于从麦克风捕获数据或通过网络实时传输音频。 . 和声(Chorus) 和声效果器会复制传入的音频, 稍微延迟重复信号, 并使用低频振荡器连续调节重复信号的音高, 然后再将重复信号(一个或多个)和原始信号混合在一起. 这就产生了一种微光效果, 并增加了声音的立体声宽度. 压缩器(Compressor) 当输入信号的幅度超过某一阈值时, 动态范围压缩器会自动衰减该信号的电平. 衰减的程度与传入的音频超过阈值的程度成正比. 压缩器的 "比例" 参数控制衰减的系数. 压缩器的主要用途之一是, 一个信号具有非常大声和小声的部分时, 压缩器可以用于降低动态范围. 降低信号的动态范围会更方便混音. 压缩器有很多用途. 例如: 它可以在主总线中用于压缩整体输出. 它可以在人声通道中使用, 使它们听起来尽可能均匀. 它可以是 Sidechained . 也就是说, 它可以利用另一个音频总线的电平来降低一个信号的电平, 进行阈值检测. 这种技术在电子游戏混音中非常常见. 在出现语音时, 音乐或音效的电平会被 "降低". 它可以通过较慢的启动(attack)来强调瞬态. 让音效听起来更有力. 延迟(Delay) 通过反馈回路添加 "回音" 效果. 它可以与 混响 (Reverb)一起使用, 模拟宽阔的房间, 峡谷等声音从远处反弹回来的地方. 失真(Distortion) 使声音失真.Godot提供几种类型的失真: overdrive , tan 和 bit cru...

Godot导出文件格式的变更

godot项目导出后,路径会有所变化,此时和编辑器内的路径已经不同,使用file_exist方法可能会失败  导出前--导出后 .png-->.png.import .jpg-->.jpg.import .tres-->.tres .gd-->.gdc .tscn-->.tscn 代码上判断需要变更为导出后的格式 if dir.file_exists(tex_path) or dir.file_exists(tex_path + ".import"): 其他格式如果不确定导出后的格式,可以在导出时选择导出pck/zip,解压后进行对比