JustAnotherGuy JustAnotherGuy - 5 months ago 48
Swift Question

How to put a node in two views?

I am using Swift 3.0, for IOS.
I Have designed a little circle node.

private var spinnyNode : SKShapeNode?

override func didMove(to view: SKView) {

// Create shape node to use during mouse interaction
let w = (self.size.width + self.size.height) * 0.001
self.spinnyNode = SKShapeNode.init(rectOf: CGSize.init(width: w, height: w))

if let spinnyNode = self.spinnyNode {
spinnyNode.lineWidth = 8
spinnyNode.run(SKAction.sequence([SKAction.wait(forDuration: 0.0000001)]))

When I use the self.addChild function, I want the node to be added to two views / scenes.

Maybe I can call the self.addChild function twice?

If anyone has any suggestions, that would be great!!

Thank you for your time.


You will need to create two nodes one in each view. Why would you want the same node in two different views? If its a game you should be able to code multiple levels in one view if that is what you are trying to do.