SKFieldNode.isExclusive = true
doesn't seem to work.
I created a very simple example in the Game Playground, with two intersecting electric fields and a third object placed at the intersection of the fields, with a negative charge.
Each field pulls the object towards its center. The first field (left side) has isExclusive=true
, the second field (right side) has isExclusive=false
.
So based on the definition, the exclusive field is suppressing any other field in its region of effect, and since the object is in both regions, it should be pulled towards the field that is exclusive.
Instead, the object doesn't move, since both fields are exerting the same forces on it.
The object gets pulled by both fields, thus not moving.
If one field is disabled using isEnabled = false
, the object immediately starts to move towards the field that is enabled.
Playground code:
import PlaygroundSupport
import SpriteKit
class GameScene: SKScene {
override func didMove(to view: SKView) {
/*
Configure two intersecting electric fields
*/
let field1 = SKFieldNode.electricField()
field1.region = SKRegion(radius: 190)
field1.position = CGPoint(x: -160, y: 0)
field1.isExclusive = true
addChild(field1)
let field2 = SKFieldNode.electricField()
field2.region = SKRegion(radius: 190)
field2.position = CGPoint(x: 160, y: 0)
field2.isExclusive = false
addChild(field2)
/*
Configure some visuals (shapes and labels) for the fields,
since SKView.showsFields doesn't work.
*/
let field1Visual = SKShapeNode(circleOfRadius: 190)
field1Visual.strokeColor = .yellow
field1Visual.addChild(SKLabelNode(text: "isExclusive=true"))
field1.addChild(field1Visual)
let field2Visual = SKShapeNode(circleOfRadius: 190)
field2Visual.addChild(SKLabelNode(text: "isExclusive=false"))
field2.addChild(field2Visual)
/*
Configure object placed at the intersection of the two electric fields,
with a negative charge, so each field attracts this object.
*/
let object = SKShapeNode(circleOfRadius: 25)
object.strokeColor = .magenta
object.physicsBody = SKPhysicsBody.init(circleOfRadius: 25)
object.physicsBody!.affectedByGravity = false
object.physicsBody!.charge = -0.1 // is attracted
addChild(object)
}
}
let sceneView = SKView(frame: CGRect(x:0 , y:0, width: 640, height: 480))
let scene = GameScene(size: CGSize(width: 1024, height: 768))
scene.anchorPoint = CGPoint(x: 0.5, y: 0.5)
scene.scaleMode = .aspectFill
sceneView.presentScene(scene)
sceneView.showsFields = true // doesn't work for electricField() and is broken for other fields
PlaygroundSupport.PlaygroundPage.current.liveView = sceneView
A bug report was also submitted on Feedback assistant, FB9661601.