salocinx salocinx - 1 year ago 147
iOS Question

Sprite-Kit: How to visualize an SKFieldNode

I am currently working on a magnetic field within my Sprite Kit game. Here's the initialization code:

private func initMagneticField(_ object: TileMapObjectMagneticField) {
let field = SKFieldNode.magneticField()
field.strength = 0.75
field.position = object.location
field.region = SKRegion(size: CGSize(width: 320.0, height: 320.0))
field.categoryBitMask = Globals.Categories.magneticField.rawValue

The magnetic field works so far, but I am unsure how to position the region property of the

Switching on physical visualisation does not show up the
region: SKRegion
nor the field node itself and the
region property
has neither

self.skView.showsPhysics = true

How to you visualise the field itself or at least the
region property
for debugging purposes ?

Answer Source

Add a child: field.addChild(SKSpriteNode(, size:CGSize(width: 320.0, height: 320.0)))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download