英文:
How to change the direction of gravity in Sprite Kit
问题
我正在尝试制作一个关于台球的游戏。屏幕就像一张桌子,重力系统的默认方向是向下,也就是Y轴。我想将这个方向改变为Z轴,这样球既具有重力效应又不会掉下来。有人知道怎么做吗?谢谢。
英文:
I'm trying to build a game about billiards. The screen is like a table, the default direction of the gravity system is downward, that is, the Y axis. And I want to change this direction to Z axis, so the ball has both gravity effect and will not fall down. Does anyone know how to do this? Thanks.
答案1
得分: 2
physicsWorld.gravity
在SpriteKit中是一个2D矢量(dx,dy),因此没有z轴的概念。
对于一个自上而下的台球游戏,你可以尝试将重力关闭 self.physicsWorld.gravity = .zero
,然后使用 velocity
和 linearDamping
来模拟台球节点的真实滚动。
英文:
physicsWorld.gravity
in SpriteKit is a 2D vector (dx,dy) and thus has no concept of the z axis.
for a top-down billiard game you might try turning gravity off self.physicsWorld.gravity = .zero
and then use velocity
and linearDamping
on your billiard ball nodes to simulate realistic rolling.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论