Building a game in SpriteKit, I used SKFieldNode.radialGravityField() with negative strength to simulate a positive charge's electric field. To visualize the fields and their interaction, I used SKView.showFields property and it was working fine.
Now, trying to implement a negative charge, I tried switching all fields to SKFieldNode.electricField(). The behavior of the fields and particles (attraction and repulsion) continued to work perfectly, but the visual representation created by showFields stopped working.
Investigating, the visual representation worked only for radialGravityField and did nothing for all other SKFieldNode options. I tried changing the fields' strength but couldn't reach anything. In addition to the fields physics working fine, I looked for the fields magnitude using SKPhysicsWorld.sampleFields(at:) and they were correct.
Example
Based on XCode's default project for iOS game, this GameScene below can reproduce the behavior. Changing from SKFieldNode.radialGravityField() to SKFieldNode.electricField() makes the fields not show up.
import SpriteKit
import GameplayKit
class GameScene: SKScene {
private var fieldNode : SKFieldNode?
override func didMove(to view: SKView) {
view.showsFields = true
self.fieldNode = SKFieldNode.radialGravityField() // Change field type here
if let fieldNode = self.fieldNode {
fieldNode.strength = 2
}
}
func touchDown(atPoint pos : CGPoint) {
if let n = self.fieldNode?.copy() as! SKFieldNode? {
n.position = pos
self.addChild(n)
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for t in touches { self.touchDown(atPoint: t.location(in: self)) }
}
}
showFieldsdebug property is broken. See feedbackassistant.apple.com/feedback/9654037