Godot教程中文版-脚本2(Scripting2)
Scripting 继续上一讲 https://github.com/okamstudio/godot/wiki/tutorial_scripting_2
Processing 处理
Godot的各个动作事件会通过回调或者虚拟函数被激发,所以没有必要在运行时写检测触发的代码。此外,更多可以做的是动画编辑器。
但是,使用脚本在每一帧中进行处理仍然是一种很常见的情况。通常有两种情况的处理:空闲处理和固定处理。
当使用Node.set_process() 设置后,空闲处理会被激活。一旦被激活,Node._process()就会在每一帧回调。
例子:
func _ready():set_process(true)func _process(delta):[dosomething..]
delta参数描述了从上一次调用Node._process()到这一次所用的时间(浮点数float类型,以秒为单位)。固定处理也是相似的,但是仅仅需要和物理引擎同步。
一个简单的测试方法是:在一个场景中创建一个标签节点,和以下的脚本:
extends Labelvar accum=0func _ready():set_process(true)func _process(delta):accum+=deltaset_text(str(accum))
一个有用的例子就是绑定敌人的场景scene,如下:
func _ready():add_to_group("enemies")
func _on_discovered():get_scene().call_group(0,"guards","player_was_discovered")
上面的函数在组“guards”的所有成员上回调了方法player_was_discovered。很明显,通过调用SceneMainLoop.get_nodes_in_group()获取“guards”的节点列表是可能的:
var guards = get_scene().get_nodes_in_group("guards")
后面会有更多和SceneMainLoop相关的东西。
func _notification(what):if (what==NOTIFICATION_READY):print("This is the same as overriding _ready()...")elif (what==NOTIFICATION_PROCESS): var delta = get_process_time()print("This is the same as overriding _process()...")
func _enter_scene():pass # When the node enters the active scene, this function is called. Children nodes have not entered the active scene yet. In general, it's better to use _ready() for most cases.func _ready():pass # This function is called after _enter_scene, but it ensures that all children nodes have also entered the active scene, and they are all functional.func _exit_scene():pass # When the node exists the active scene, this function is called. Children nodes have all exited the active scene at this point.func _process(delta):pass # When set_process() is enabled, this is called every framefunc _fixed_process(delta):pass # When set_fixed_process() is enabled, this is called every physics framefunc _paused():pass #Called when game is paused, after this call, the node will not receive any more process callbacksfunc _unpaused():pass #Called when game is unpaused
Godot教程中文版-脚本2(Scripting2)相关推荐
- GraPhlAn教程中文版——超炫物种树进化树绘制
文章目录 GraPhlAn教程中文版 概述Overview 介绍Introduction 安装Installation 方法1. Bioconda快速安装 方法2. Mercurial下载 方法3. ...
- pytorch官方教程中文版(二)学习PyTorch
pytorch编程环境是1.9.1+cu10.2 建议有能力的直接看官方网站英文版! 下面所示是本次教程的主要目录: pytorch官方教程中文版: PyTorch介绍 学习PyTorch 图像和视频 ...
- 撒花!PyTorch 官方教程中文版正式上线,激动人心的大好事!
点击上方"AI有道",选择"星标"公众号 重磅干货,第一时间送达 什么是 PyTorch?其实 PyTorch 可以拆成两部分:Py+Torch.Py 就是 P ...
- 简明python教程-简明Python教程-中文版.pdf
您所在位置:网站首页 > 海量文档  > 计算机 > Python 简明Python教程-中文版.pdf152页 本文 ...
- OpenCV官方教程中文版
OpenCV官方教程中文版(For Python) OpenCV2-Python-Tutorials 段力辉 译 说明:搬运自linux公社pdf文件,粗略搬运,仅作个人笔记参考,有时间再美化 部分文 ...
- Kaldi入门教程 aishell脚本
Kaldi入门教程 aishell脚本 文章目录 Kaldi入门教程 aishell脚本 @[toc] 准备词典 准备数据,分为test.dev.train集 词典.语言文件准备,生成对应的数据关系 ...
- pytorch官方教程中文版(一)PyTorch介绍
pytorch编程环境是1.9.1+cu10.2 建议有能力的直接看官方网站英文版! 下面所示是本次教程的主要目录: pytorch官方教程中文版: PyTorch介绍 学习PyTorch 图像和视频 ...
- python官网 中文版-python .. 官方教程中文版.pdf
您所在位置:网站首页 > 海量文档  > 计算机 > Python python .. 官方教程中文版.pdf105页 ...
- 面向开发人员的 ChatGPT 提示词教程中文版 - ChatGPT 版
面向开发人员的 ChatGPT 提示词教程中文版 - ChatGPT 版 1. 指南 1-1. 提示的指南 1-2. 配置 1-3. 提示语原则 原则 1: 写出清晰而具体的指示 技巧 1: 使用分隔 ...
最新文章
- JavaScript 工作原理之五-深入理解 WebSockets 和带有 SSE 机制的HTTP/2 以及正确的使用姿势(译)...
- python工程师待遇-Python工程师待遇如何 玩转Python看这里
- 轮距和轴距有什么区别_迈巴赫S级推“婚庆版”?轴距超3.3米 612马力配全时四驱...
- python核心编程第三版_《Python核心编程(第3版)》
- 解决Windows下运行出现ModuleNotFoundError: No module named xxx问题
- linux find 命令详解
- ZooKeeper官方文档学习笔记03-程序员指南
- C++小游戏——24点
- 大数据、Hadoop、Hbase介绍
- 2005/2006/2007/2008/2009/2010/2012/2013/2014/2015/2016/2017/2018/2019/2020高德poi 一级类别 二级类别
- 知识图谱05:知识图谱构建涉及的技术
- socks5认证过程
- springboot word excel ppt 图片aspose 转换PDF 在线预览
- flappy bird用java实现_java实现Flappy Bird游戏源代码
- 尚品宅配、欧派激战整装市场
- disallow php,在robots.txt中Disallow: /abc和Disallow: /abc/的区别
- pip install pyinstaller安装报错
- 无线网服务器断开怎么回事,无线网自动断开怎么回事
- 图像处理领域顶级期刊及会议
- 【建议收藏】数据结构和算法面试题