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游戏开发经典实例
208
6
animatedSprite.run(SKAction.repeatForever(animationAction))
讨论
SKAction
类能够实时改变精灵的纹理贴图。如果我们想基于连续位图来生成动画,
我们所需要做的仅仅是将所有位图转换为
SKTexture
对象,然后保存到一个数组中。
调用
animate(with:, timePerFrame:)
法创建动画动作时,我们将这个数组以
及一个平均帧播放时间作为参数传递给它。假设我们需要让动画以
30
/
秒的速
度播放,则每帧的平均播放时间为
1/30
秒(
0.033
/
帧)。
要获得
SKTexture
象以便渲染,我们可以用
SKTexture
SKTexture(imageNamed:)
初始化方法,也可以通过包含它们的纹理图集来获得。我们曾经在本章
6.11
节中
讨论过纹理图集,这是一种将帧动画进行集中管理的绝好办法。它不但节省内存,
而且能保证动画中的每一帧都不会被丢失,当动画加载比较多的帧时游戏不会因此
出现短暂卡顿。
6.19
视差滚动
问题
通过
Sprite Kit
,我们想显示一个
2D
场景,但同时也要具有一定的深度,即当镜头
移动时,远处的物体比近处的物体要移动得慢。
解决方案
实现视差滚动的方法依赖于游戏的细节。在这个答案里,我们会创建一个包含
4
部分的场景,根据距离远近的不同,依次为:
一条山间土路。
旁边的山峦。
远处的山峦。
天空。
2D
图形和
Sprite Kit
209
场景的最终效果如图
6-5
所示(下面这张图片不会滚动,除非你拥有魔法 ...
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