Godot 实践 Q & A

作者:Justus
2018-10-10
27 21 2

Godot 3.0.6

1. _enter_tree() vs _ready()

[reddit] enter_tree() vs. ready(), etc. Are there rules of thumb regarding which initialization function to do my housekeeping?

2. 如何用脚本 connect signals?

[reddit] explain to me how to use the signals in Godot, please.

3. collision layer 和 collision mask 有什么区别

[GodotQ&A] What's the difference between Collision layers and Collision masks?
[GodotQ&A] Collision masks and its propper uses

4. 如何在 pc 上打开触屏模式?

Project Settings->Display->Emulate Touchscreen
[GodotQ&A] How can i show touch screenbuttons only on android devices?

5. 为什么 tilemap 会闪烁

Open issue, 把 quadrant size 设为1就不闪了
[GithubIssue] Tilemap/draw_rect random flickering with Nvidia drivers

6. windows 平台的导出 exe 图标设置没有效果

godot 已知 bug,自己用 resource hack 改

Resource Hacker 简介

A freeware resource compiler & decompiler for Windows® applications
Resource Hacker HomePage

7. NavigationPolygonInstance 为什么无法多个同时起效?

注意拼接要严丝合缝,即相邻边拥有共同顶点。
[Blog] [godot]navigation2d 的一些坑

8. 如何用 print 格式化输出?
print("%s" % value)  
print("%s...%s" % [value1,value2,...])
9. 两个引用所指的碰撞对象是不是同一个,有什么办法判断吗?

Resource Id.

CollisionObject.get_rid().get_id()
CollisionObject2D.get_rid().get_id()
10. 有什么方式记录下 collisionLayer 的用途约定么?

有。给每个 layer 命名。
Project Settings->General->Layer Names

11. free() vs queue_free()
12. 为什么 RayCast/RayCast2D 只有 Collision Mask 而没有 Collision Layer? 这意味着什么?

这意味着其他人不能决定自己是否和 raycast 碰撞,只有 RayCast 可以决定自己打算和处于哪些 Layer 的对象碰撞。

13. 为什么 Godot 没有现成的 FSM?这会影响它的易用性么?

J: 我不知道。不会影响易用性。
因为动画系统通常包含着一个天然的 FSM,除了 transition。Godot 在之后的版本中会加入一个与动画系统协作的状态机。但这并不是很有必要。
因为对于简易的状态机而言,几乎总是能用 enum 加一个状态转移方法来完成。对于复杂的状态机而言,动画系统的状态和实际的逻辑状态机通常会不一样,并且 FSM 在并发和层次用途同时出现的情况下并不是最好的选择。 个人推荐仅在简单和并发状态下考虑状态机。通常层次状态机的场景你可以通过一些设计来改变成并发状态。
如果你真的寻求复杂的决策实现并且被层次状态机的可扩展性弄得精疲力尽,那么推荐使用行为树(behavior tree)

14. 什么是行为树?Godot 3有现成的实现么?

一种 AI 算法。
一种梳理逻辑决策的解决方案。
它解决的问题与复杂的状态机类似。通常由一个树结构+黑板来实现。
Godot 中没有内置的实现。有其他开发者提供的插件实现(Godot 3可用)。
开发者务必阅读链接文章。如果你毫无编程经验,那么请向你家的软件设计师寻求符合你需要的简单解释。在一些游戏引擎中会内置 BT 功能,他们的文档也许是不错的选择。

行为树参考:
[Wikipedia] Behavior tree (artificial intelligence, robotics and control)
Behavior trees for AI: How they work
[SO] Behavior Tree Implementations

15. 默认函数_xxxx在子类中如何被调用?

总是在子类的覆写实现之前自动被调用。

Remember that default functions like _init, and most notifications such as _enter_tree, _exit_tree, _process, _physics_process, etc. are called in all base classes automatically. So there is only a need to call the function explicitly when overloading them in some way.

[GodotDocs] GDScript

16. 如何设置新的随机种子?

randomize()

17. 如何设置断言?

assert a==b

18. 如何获取 run time type?

is
get_class()

19. 如何脚本创建 timer?

get_tree().create_timer(1.5)

20. 某个节点如何获取编辑他的场景的根节点?

Node.owner

21. 如何使用 AutoTile?

[GodotQ&A] How do I use the AutoTile in Godot 3.0?

22. 使用其他线程创建实例为什么感觉这么慢?

对,是个已知问题。
[GithubIssue] Multithreaded instancing performance (RID caching needs to be completed) #10970 
[blog] 关于 godot 中多线程生成场景加入主场景问题

23. Tiled 可以和 godot 3一起工作么?

可以,AssetLib 搜索插件 Tile Map Importer。
[Youtube] How to Import Maps from Tiled in Godot
[reddit] Importing from Tiled with collisions?

24. set_process,set_physics_process,set_process_input 是默认为 true 的吗?

是的。不同于 Godot 2, 在 Godot 3中他们默认为 true。

25. 什么情况下属性的 setter,getter 才会被调用?

外部访问时。内部用 self.prop1的方式访问时。

26. gdscript 有哪些内建函数可用?

[GodotDocs] @GDScript

27. gdscript 有访问限定符么?没有的话如何控制访问权限?

没有 access modifier.
语法上不能控制。设计上依然可以通过良好的约定和命名法来表征设计约束。
Keep it simple and stupid.
[Widipedia] Access Modifiers
KISS (Keep it Simple, Stupid) - A Design Principle

28. 为什么我的派生场景无法访问父场景的成员变量?

情况之一: 如果你的父场景自带一个脚本,派生场景不带脚本,会无法访问。这种情况下,应取消父场景中脚本的绑定,在子场景中重新绑定一次父脚本或者创建一个继承于父脚本的新脚本。
[GithubIssue] GDScript: Parent variables aren't accessible in sub classes

29. 为什么 godot 编辑器对我的键盘输入没反应了?

切换完输入法以后请额外按一次 Ctrl 以解除这个状态。

30. 如何全局自定义鼠标光标? (为什么它不工作?)

TBD
[GodotDocs] Customizing mouse cursor

31. 关于 svg 格式的支持

[GodotQ&A] Is there .SVG file support for Godot?

32. 如何得到 String 中的每一个字符?

[GodotQ&A] How to split a string character by character?

33. 如何得知 node 是否被 free?

[GodotQ&A] How to know a node is freed (or deleted)

34. 如何检查手柄是否连接?

[GodotQ&A] Check if Controller connected or not

35. 如何检查一个变量是否存在?

if "varName" in get_parent(): print("varName is defined in parent!")
[GodotQ&A] Check if script of a node has variable

36. 为什么游戏总是会对手柄输入进行响应,即使窗口已经失去焦点?有什么办法能控制是否屏蔽这种行为么?

取决于 OS 的处理,通常 OS 总是会把手柄响应发给程序,而键盘输入则不同。
如下方法可以获知焦点状况。

func _notification(what):
    if what == MainLoop.NOTIFICATION_WM_FOCUS_OUT: 
        Unfocused = true
    elif what == MainLoop.NOTIFICATION_WM_FOCUS_IN: 
        Unfocused = false

[GithubIssue] Games receive joypad input even if the game window is not focused

37. 如何导出 Android apk?

导出三件套

38.只在 networking 时才出现 error: Script inherits from native type 'Reference', so it can't be instanced in object of type: '<ANodeType>'?

请不要将节点实例的引用直接作为 rpc 方法的实参广播出去。

39.为什么使用 strech mode: 2d 进行缩放窗口的时候性能会损耗?

纯2d 游戏请使用 viewport 缩放模式,详情参见文档。
[GodotDocs] Multiple resolutions

Godot 3.1

1. 如何使用3.1新特性 typed GDScript?

LEARN TO WRITE TYPED GDSCRIPT IN GODOT 3.1

Networking

1. localhost、127.0.0.1 和 本机 IP 三者的区别?

[知乎] localhost、127.0.0.1 和 本机 IP 三者的区别?
[百度知道] localhost,127.0.0.1 和 本机 IP 三者的区别

一般话题

1. 如何在 GLSL 中将 RGB 值转化为 HSV?

[SO] From RGB to HSV in OpenGL GLSL

2. 如何描述 FSM?该从哪里开始?

可以使用 UML 来描述。
[Wikipedia] Unified Modeling Language
[Wikipedia] UML state machine
State Machine Diagram Tutorial
[blog] 【学习小记】UML——状态机图

Git

1. fast forward 是什么?

Git fast forwards and branch management

2. rebase 是什么?

Merging vs. Rebasing
Don't Be Scared of git rebase

MarkDown

  1. 关于 MarkDownDaring Fireball: Markdown Syntax Documentation

Other Tools

1. 有哪些开源免费的绘画工具?

GIMP, Krita, Aseprite
GIMP - GNU Image Manipulation Program
Krita | Digital Painting. Creative Freedom.
Aseprite - Animated sprite editor & pixel art tool

2. 有哪些 tilemap 编辑器?

Tiled Map Editor | A flexible level editor
[Docs] Tiled Documentation

3. 制作系统 UML 图和 FSM 图有什么工具吗?

VP Online
Lucidchart: Online Diagram Software & Visual Solution

4. 常见游戏术语的定义

Gaming Dictionary

5. 动作设计软件

MakeHuman
[Youtube] MakeHuman 1.1 -- A Completely Free 3D Character Creator
design doll
[Youtube] [TUTORIAL] Design Doll
iclone
Daz3D
Daz3D Documentation Center

6.函数绘制

Desmos

7.界面设计原型工具

Pencil Project

近期点赞的会员

 分享这篇文章

您可能还会对这些文章感兴趣

参与此文章的讨论

  1. SASAMA18 2018-10-10

    界面设计原型工具想补充一个Axure

    • Justus 2018-10-13

      @SASAMA18:谢谢,已在原日志中补充。

您需要登录或者注册后才能发表评论

登录/注册