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游戏开发经典实例
使用外设
307
大屏有利于同时展示给多个人
大屏电视前一般都会摆放沙发,沙发上可以坐许多人。也就是说,可以多人同
时玩一个游戏,当然,只有一个设备的内容可以投影到电视机上。
讨论
一般,能够同时在
iPhone
iPad
上运行的游戏会更好卖一些。不同的玩家有不同
的偏好,有的玩家购买了
iPhone
,有的玩家购买了
iPad
,很少有人两者都有,因为
苹果的产品价格都不低。
至于支持大屏显示器,这个特性确实很酷,不过这种需求并不普遍。除非你专门设
计一个给多个玩家在同一个房间内玩的游戏,不然你不会觉得支持外接显示器是一
个必不可少的功能。
10.6
拖放
问题
我们想将一个对象拖放到指定位置。如果对象被拖到它不可能到达的位置,则它应
该回到原来的位置(尤其对于卡牌类游戏来说)。
解决方案
本例显示如何编写自己的拖拽效果。当然,在
iOS
中有内置的拖拽机制,它
主要针对需要在不同
APP
间共享内容的
APP
,或者需要在一个
APP
不同部
分之间共享内容的情况,它的
API
主要都是用于封装要传输的数据的。
如果你对这个感兴趣,苹果的文档(
https://apple.co/2Ihvu0k
)是最好的帮助。
用手势识别器就可以实现拖放。当手势识别结束,判断拖放的位置是否是一个有效
目的地,如果是,将被拖放的
View
放到该位置,否则,又放回它原来的位置。
下列代码提供了一个现成的例子。这个例子中,点击
CardSlot
对象(即牌墩)会
生成一堆牌,这些牌(或
Card
对象)可以被拖到其他
CardSlot
对象中,前提是这
CardSlot ...
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