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游戏开发经典实例
性能和调试
331
子:当我们打开一个
iOS
程序时,系统会首先显示一张
App
的启动图片。苹果鼓
励开发者将这张启动图片设计得就像
App
的一部分,但这张图片上不需要显示任
何文字和数据,这样会让
App
的启动过程看起来加快了。
最后,还有一种例子是,我们只需要在屏幕上显示部分细节就可以让玩家开始游戏,
当然在游戏开头的几秒钟内,画面效果会稍差一些,但这也是可以忍受的。这种技
术被称作“纹理流”,这种办法实际上在加载过程中首先加载一些事先设计的小尺
寸的图片,然后在玩家进入游戏后,再在后台进程中加载全尺寸的高清图片。
纹理流可以让游戏在正式开始前加载的速度加快,因为需要传输的数据变少了。但
是,它同时带来了一些视觉问题:当更大的、画质更高的图片加载完成后,会出现
一种视觉“凸现”的问题。另外,由于需要同时加载相同图片的不同版本,也会增
加内存的消耗,这会在
iOS
设备上导致内存不够的问题。
11.3
解决内存不足问题
问题
当图片或其他资源加载到内存中时,
App
会随机地崩溃。
解决方案
降低
App
的内存占用有几种方法,例如:
使用更小的图片
在多个角色和贴图中重用同一张图片,比使用多张只有细微差别的图片要好。
裁剪图片
如果有一张图片,它的边缘是透明区域,则我们可以将这些透明边缘裁掉。因
为当图片被加载时,每个像素都会占用的内存,包括完全透明的像素。
使用纹理图集
如果使用了
Sprite Kit
,在
Xcode
中创建纹理图集是很容易的。纹理图集将多张
图片整合到一起,因为每张图片占用的空间都是最小的,所以它能加载得更快。
Xcode ...
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