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游戏开发经典实例
184
6
然后运行应用程序。你只会看到一个空白的窗口,但一旦你在窗口中加入一些内容
(接下来的内容中我们会讨论),在屏幕的右下角,你就会看到一些额外的信息,
显示当前游戏运行的性能。
讨论
SKView
是一个容器,在这个容器中显示
Sprite Kit
元素。所有的二维图形都绘制在
SKView
中。
SKView
UIView
的子类
,因此我们可以在
IB
中使用它。因为大部分时候我们都
想以全屏的方式显示
SKView
,因此我们会把
View Controller
的根视图设置成一
SKView
与之相对的,我们还可以把一个
SKView
View Controller
根视图的
subview
中去)。
默认情况下,
SKView
不包含任何内容
;我们需要在上面放置要显示的内容。在这里,
我们演示了如何显示一些调试信息:
FPS
(屏幕每秒钟内所能绘制的屏幕帧数,单
位为:帧
/
秒),
draw
方法调用次数,以及屏幕上节点数。需要注意的是,如果屏
幕上没有任何东西显示时,这些调试信息也不会显示,这些信息只会在屏幕上有真
正需要渲染的内容时才显示。
6.3
创建场景
问题
我们需要显示一个场景,场景是一个
SKView
中所有
sprite
(精灵)的集合。
解决方案
创建一个新类,继承
SKScene
。这里,我们不妨把这个类命名为
TestScene
。将该
类定义为
SKScene
的子类。确保导入了
SceneKit
框架。
TestScene
添加一个属性:
var contentCreated = false
2D
图形和
Sprite Kit ...
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