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游戏开发经典实例
游戏的设计
25
解决方案
通过一个
Bool
变量来保存游戏的“暂停”状态。然后,将游戏对象分成两种类别,
一类在暂停的时候继续运行,另一类在暂停的时候停止运行:
for gameObject in gameObjects {
//
如果游戏不在“暂停”状态,而且这个游戏对象不支持暂停,
//
则该对象继续刷新
if paused == false || gameObject.canPause == false {
gameObject.update(deltaTime: deltaTime)
}
}
讨论
暂停游戏的最简单办法,是用一个变量记录游戏的暂停状态;当游戏刷新时,检查
这个变量的值,为
true
的时候我们停止任何游戏对象的刷新。
当然,我们并不想让游戏中的每一样东西都被“冻”住。例如这些:
用户界面仍然要能够继续工作。
网络需要继续和其他计算机保持连接而不是完全断开。
这时,最好让某些对象永远不会被暂停。
1.10
记录游戏时间
问题
记录游戏从启动以来,总共用去了多少时间。
解决方案
在游戏启动时,创建一个
Date
对象并将它保存起来:
//
声明一个属性,用于游戏启动时记录启动时间
var gameStartDate : Date?
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