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游戏开发经典实例
198
6
解决方案
创建一个名为
Textures.atlas
的文件夹,把所有的纹理图片放到其中。
然后,通过将文件夹拖到项目导航窗口的办法,将文件夹添加到项目中。
讨论
一个纹理图集也是一个纹理图片,它会由许多小的纹理图片构成。纹理图集的使用,
意味着我们将用单一的较大的图片取代多个小图片。纹理图集比起多个小图片要省
内存,最重要的一点是它渲染的效率更高。当真正绘制精灵时,所用到的图形实际
上仅仅是纹理图集中的一小块区域。
如果我们的游戏中包含许多不同的精灵,每种精灵又使用不同的图片,则每当
Sprite Kit
渲染到一种新的精灵时,都需要切换不同的图片。每次图片的切换都会
带来一小点性能上的损失,一旦切换次数过多,则这些性能损失就会叠加起来。但
是,如果所有的精灵都使用同一个图片,则
Sprite Kit
就完全不需要切换图片,从
而使渲染的速度变快。
当我们把图片放到一个名称后缀为
.
atlas
的文件夹中,并开启
Texture Atlas
Generation
选项,
Xcode
会自动用文件夹中的图片产生一个纹理图集。所有的图片
都会被自动裁剪成透明背景图片以减少像素的浪费,并且所有的图片都会以尽可能
紧凑的方式拼接在一起。
当我们使用了纹理图集后,
Sprite Kit
代码仍然无需改变。下列代码无论是否使用
纹理图集都能正常运行:
let imageSprite = SKSpriteNode(imageNamed: "Spaceship")
6.12
形状节点
问题
我们想使用形状节点来绘制矢量图形。
2D
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