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游戏开发经典实例
224
7
一旦物体已经被创建好之后,我们就不能修改物体的碰撞体形状了。如果我
们要让精灵变成另外一个形状,只能替换精灵的
SKPysicsBody
7.5
速度
问题
我们想让一个物体以指定速度、沿指定方向开始运动。
解决方案
要改变一个物体的速度,可以修改它的
velocity
属性:
//
开始以每秒
500
个单位的速度移动(极快)
sprite.physicsBody?.velocity = CGVector(dx: 0, dy: 500)
讨论
改变一个物体速度的最简单方法是直接修改它的
velocity
属性。这是一个
CGVector
类型,以像素
/
秒为单位表示移动速度。
注意,直接修改速度能达到一种很好的效果,我们可以用这种方式设置物体的初速
度。例如,我们想让火箭一离开发射器,就以非常快的速度移动。我们可以创建一
个火箭精灵,然后立即设定它的
velocity
属性,这样它就会开始移动。
如果想让它的移动变得更真实,可以在这个物体上施加一个力(参见
7.14
节)。另外,
如果想精确地逐帧控制物体的移动,可以将物体设置为静止物体(参见
7.3
节),
可以手动修改物体的位置或者使用动作
SKAction
(参见
6.9
节)。
7.6
质量
大小和密度
问题
我们想指定物体的重量。
物理学
225
解决方案
设置物理体的
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