问题标签 [skfieldnode]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
133 浏览

ios - 磁场影响不需要的精灵

我有一个玩家精灵,当用户在屏幕上拖动手指时它会移动。我已经实现了玩家精灵在其周围产生磁排斥力的能力。我的困境是,当电源打开时,玩家精灵本身会在不应该影响我的时候受到影响。

我已经在所需的精灵和字段节点上设置了正确的fieldBitMaskcategoryBitMask,但仍然无法正常工作。这是我的玩家physicsBody配置:

0 投票
1 回答
1117 浏览

ios - Sprite-Kit:如何可视化 SKFieldNode

我目前正在我的 Sprite Kit 游戏中研究磁场。这是初始化代码:

磁场到目前为止有效,但我不确定如何定位SKFieldNode对象的区域属性。

打开物理可视化不会显示region: SKRegionnor 字段节点本身,并且region propertyhas not sizenorposition属性:

您如何可视化字段本身或至少region property用于调试目的?

0 投票
0 回答
87 浏览

ios - 如何在屏幕边缘设置排斥屏障?

通过这个函数,我试图初始化围绕我的屏幕边缘的四个 SKFieldNode 并向内施加一个力。这样,没有物体会粘在边缘。但是,当我确实将一个物体撞到屏幕边缘时,它只会坐在那里,感觉不到排斥力。我已将它们的 categoryBitMask 添加到对象的 collisionTestBitMask 中,因此它知道要击中它们。此外,随着节点数增加四个,它们也在现场。他们的位置、场强或矢量箭头有问题吗?

0 投票
1 回答
89 浏览

ios - 通过 SKFieldNode 创建一个吸引到较大节点的 SKNode,而不移动较大的节点

在我的游戏中,我有一个更大的 SKNode,它使用 SKFieldNode 径向重力场来吸引其他更小的节点。这导致较大的节点被较小节点的力移动,这对我的游戏来说不是最佳的。(作为参考,这是在没有重力的物理世界中)。

有没有办法使用 SpriteKit 将节点吸引到一个字段中而不移动一个特定的节点,并让它在物理模拟中仍然响应,这样它们就可以保持接触较大节点的边缘而不影响它?

0 投票
1 回答
15 浏览

swift - How to exclude positions in a field in SpriteKit?

I have a function that spawns little balls, randomly positioned, on the screen. The problem I face is that I want to distribute the balls randomly, but when I do so, some balls spawn on top of each other. I want to exclude all the positions that are already taken (and maybe a buffer of a few pixels around the balls), but I don't know how to do so. I worked around this by giving the balls a Physicsbody, so they move off from one another if they happen to spawn on top of each other. But I want them to not spawn on top of each other in the first place. My code for now is the following:

I don't know if this problem should be solved by having an array that stores all taken positions, or if I should use some kind of FiledNode, where occupied space can be sort of subtracted, but sadly I am unfamiliar with FieldNodes, so I don't know if that's the right way to face the problem.

0 投票
1 回答
28 浏览

ios - 当显式设置精灵的速度时,使 SKFieldNode 影响 SKSpriteNode?

我有一个 SpriteKit 场景,其中一个SKFieldNode.linearGravityField(withVector:)SKSpriteNode一个physicsBody. 用户用手指移动精灵。

我通过显式设置其velocityin来移动精灵update(_:),这会导致一个问题:当用户的手指触摸屏幕时,该字段不会影响精灵,因为我的代码会覆盖它。当用户的手指没有触摸屏幕时,该字段将按需要工作。

这是我设置精灵的方式velocity

以下是我创建该字段的方式:

问题:即使精灵被用户移动,我如何才能使该字段影响精灵?

谢谢!