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游戏开发经典实例
物理学
219
碰撞体
碰撞体定义了物体的形状。常见的形状如正方形、矩形、圆形和多边形。在
Sprite Kit
中,所有物体都有碰撞体,它在我们创建物体时定义(在其他一些物
理引擎中,物体和碰撞体是不同的概念)。
边缘碰撞体
边缘碰撞体是一种碰撞体,它由一条或多条细线构成。边缘碰撞体在创建墙或
障碍物时非常有用,因为它们一般都非常简单且便于模拟。具有边缘碰撞体的
物体永远不会运动,它是静态物体。
碰撞
当两个物体发生接触时,我们称之为碰撞。注意,碰撞和碰撞体是不同的概念,
碰撞是一个会发生的事件,而碰撞体仅仅是一个形状。发生碰撞时,我们可以
从碰撞中获得这些信息,如发生碰撞的是哪些物体,它们碰撞的位置等。
连接
连接是两个物体之间的一种关系。存在有几种不同的连接。常见的是“
pin
”连
接,即一个物体能够旋转,但不能从另一个物体的某个相对点离开。另一种是
spring
”连接,一个物体能够离开另一个物体,但当它运动到距离另一个物
体的某个范围时,它又会被弹回第一个物体。
7.2
为精灵添加物理特性
问题
我们想让精灵受重力和其他物理力量的影响。
解决方案
要让一个
SKSpriteNode
具有物理特性,需要创建一个
SKPhysicsBody
对象,然后
赋给节点的
physicsBody
属性:
// scene
是一个
SKScene
对象
let sprite = SKSpriteNode(color:SKColor.white,
size:CGSize(width: 100, height: 50)) ...
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