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游戏开发经典实例
248
8
8.3
显示
3D
对象
问题
我们想在屏幕上绘制
3D
对象。
解决方案
首先,定义一个几何对象,用于向
Scene Kit
描述该对象的形状或者外观:
let capsule = SCNCapsule(capRadius: 2.5, height: 6)
然后,用这个形状来创建一个节点对象(
SCNNode
),设置节点的位置,然后将节
点添加到场景中:
let capsuleNode = SCNNode(geometry: capsule)
capsuleNode.position = SCNVector3(x: 0, y: 0, z: 0)
scene.rootNode.addChildNode(capsuleNode)
讨论
节点(
SCNNode
)是不可见对象,它仅用于表示在某个位置中占据的一定空间。就
其本义而言,节点什么也不是,要让节点能够被用户所见,我们必须将它和各种对象,
如几何形状、镜头、灯光等联系在一起。我们将在本章的其他问题中介绍这些对象。
节点可以拥有其他节点。这就能让我们将多个对象组合在一起:如果我们移动这个
节点,所有添加到它上面的子节点都会随着一起移动。这个特点使我们很容易就创
建复杂场景,同时还能对节点进行管理。
场景包含了一个叫作“根节点”的节点。如果我们想将一个节点放进某个场景中,
我们需要在场景的
“根节点”上调用
addChildNode
方法才能将这个节点添加到场
景中。
8.4 Scene Kit
的镜头
问题
我们想在
3D
场景中通过镜头来控制玩家的视角。
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