Skip to Content
Swift游戏开发经典实例
book

Swift游戏开发经典实例

by Jonathon Manning, Paris Buttfield-Addison
January 2020
Intermediate to advanced
356 pages
6h 4m
Chinese
China Electric Power Press Ltd.
Content preview from Swift游戏开发经典实例
340
11
讨论
编译器提供了一些“魔术”变量,它们会根据你在代码中使用的地方的不同,输出
不同的值。
例如
__LINE__
量总是表示正在被编译的文件的当前行号
__FILE__
量则表示
正在被编译的源文件的完整路径。
__FUNCTION__
量表示当前函数名。
__LINE__
__FILE__
__FUNCTION__
被用在函数中作为参数的默认值时,
将用调用者的行号、文件名和函数名来作为输出,而非使用这些变量来定义
的函数的行号和文件名。
在这个例子中,我们使用了一些易读的代码来进行日志输出。我们提到过
__
FILE__
变量包含了正在编译的文件的完整路径,但这个路径一般都会很长,绝
大多数情况下,我们只需要输出文件名就可以了。要得到文件名,我们可以调用
lastPathComponent
方法,这个方法返回文件路径中的最后的文件名部分。
11.8
创建语音断点
问题
当游戏中发生某些状况时,我们想接收到语音播报通知。
解决方案
添加一个语音断点,同时不中断游戏运行。步骤如下:
1.
在需要发送通知的地方加一个断点。
2.
在断点上点击鼠标右键,然后选择
Edit Breakpoint
。断点编辑对话框将显示。
3.
勾选“
Automatically continue after evaluating actions
”。
4.
点击
Add Action
+
号按钮)。
5.
Action
类型从
Debugger Command
修改为
Log Message
6.
在文本框中输入需要发出语音的文字内容。
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

精通機器學習

精通機器學習

Aurélien Géron
FreeBSD® Unleashed

FreeBSD® Unleashed

Brian Tiemann, Michael C. Urban
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
Swift学习手册

Swift学习手册

Jon Manning, Paris Buttfield-Addison, Tim Nugent

Publisher Resources

ISBN: 9787519840129