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游戏开发经典实例
2D
图形和
Sprite Kit
183
还有一种常见的矩阵,叫作透视投影变换矩阵,当对象从原点逐渐移远后会变小。
你可以用一个向量乘以透视投影变换矩阵,就像其他变换一样。
与此相对的,还有正交投影变换矩阵,无论如何向远处移动对象,它们的大小都不
会改变。这两种情况,都需要定义视图区域的高和宽,所有位于这个区域之外的东
西都是不可见的。
有了这些数学基础,再来继续我们的问与答。
6.2
创建
Sprite Kit
视图
问题
如何用
SKView
来显示二维图形?
解决方案
要使用
Sprite Kit
中的对象,需要导入
SpriteKit
模块。在源文件中加入这一句:
import SpriteKit
打开故事板,选中一个
View Controller
对象。展开这个
View Controller
,选中下面
View
,将它的
class
改为
SKView
至少需要在一个源文件中加入
SpriteKit
框架的导入语句。否则,
Xcode
行的时候不会将
Sprite Kit
框架连接到你的代码中,这样,当视图加载时,
SKView
类将无法加载,
App
会崩溃。
然后,在
View Controller
的源文件中,在
viewDidLoad
方法中加入以下代码:
if let spriteView = self.view as? SKView {
spriteView.showsDrawCount = true
spriteView.showsFPS = true
spriteView.showsNodeCount =
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