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游戏开发经典实例
24
1
如果想彻底不再接收重绘通知,可以调用
CADisplayLink
invalidate
方法:
//
移除重绘通知,
//
然后释放对象
displayLink?.invalidate()
displayLink = nil
讨论
当我们提到“实时”游戏的时候,往往联想到的就是玩家、车辆及其他会动的东西
在屏幕上到处乱跑的画面。似乎这些东西是在持续运动着的。但实际上,这不过是
屏幕以
1/60
秒的速度重绘屏幕图像的结果。每当绘制一帧,屏幕上的对象都会改
变它们的位置。当这个绘制的速度足够快时,人的肉眼就会被欺骗,看起来就像是
物体在持续运动。
实际上,我们的游戏刷新速度并不一定需要达到
1/60
秒那么快。只要超过
每秒
25
帧(或者每
1/25
秒刷新一次)就足以造成持续运动的效果。但是,
刷新得越快,造成的动画效果就越平滑,但是对于游戏而言那是不可能的,
通常每秒
30
帧就差不多了。
当我们将游戏刷新速度提高到屏幕刷新率那么高时,我们会得到最好的游戏效果。
为达到这个目的,我们可以使用
CADisplayLink
,它通过
Core Animation
来获知屏
幕绘制时间。每当屏幕重绘时,
CADisplayLink
就向你指定的目标对象发送一个方
法调用。
值得注意的一点是,你想创建多少
CADisplayLink
对象都可以,当然这些对象会在
同一时刻发送屏幕重绘通知。
1.9
游戏暂停
问题
有时候我们需要使游戏的一部分功能暂停,而另一部分仍然可以继续运行。
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