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游戏开发经典实例
176
6
6.1
熟悉二维数学
在使用
2D
图形框架时,了解一些关于平面数学的知识是非常重要的。
坐标系
2D
图形框架中,用两个维度来描述空间的概念:
x
轴和
y
轴。
x
轴是一条从左向
右横向贯穿的水平轴,而
y
轴是一条从上到下垂直贯穿的垂直轴,我们将这种空间
称为坐标系。在这个坐标系中,位于中心的点叫作原点。
要描述位于一个坐标系中的确定点的位置,我们只需要两个数字:这个点在水平轴
上的投影与原点之间的距离(即
x
轴坐标),以及这个点在垂直轴(即
y
轴坐标)
上的投影与原点之间的距离。这两个坐标常用圆括号包裹在一起,如:(
x
坐标,
y
坐标)。
例如,从原点开始向上
5
个单位,向右
2
个单位的点的坐标写为:(
5
2
)。原点
自身坐标以(
0
0
)表示,也就是说,原点位于横坐标为
0
、纵坐标也为
0
的位置。
三维坐标空间和二维坐标空间类似,但有一个最大的不同:它多出了一个坐
标轴,叫做
z
轴。在三维坐标系中,一个三维坐标需要用
3
个数字表示:(
0
0
0
)。
向量
简单地说,一个向量是一个值,它包含了
2
个或更多的值。在游戏中,向量通常用
来描述
2
个东西:位置(如坐标)、速度。
一个空的两维向量,它的两个值都是
0
,可以记作:
[0,0]
iOS
中,我们可以用
CGPoint
结构表示二维向量,如图
6-1
所示:
let myPosition = CGPoint(x: 2, y: 2)
我们还可以用向量来表示速度。速度表明了一个点在单位时间内移动的距离;例如,
2D
图形和
Sprite Kit
177
一个物体每秒钟向右移动
3
个单位,向下移动 ...
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