如何在Sprite Kit中改变重力方向

huangapple go评论52阅读模式
英文:

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,然后使用 velocitylinearDamping 来模拟台球节点的真实滚动。

英文:

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.

huangapple
  • 本文由 发表于 2023年2月13日 22:53:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75437505.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定