I am making a game and have a bunch of vectors with each index corresponding to an SKSpriteNode within another vector. Can you extend the SKSpriteNode class to include the properties that I have stored in other vectors in corresponding indexes, then create objects of type ExtendedSKSpriteNode within the class declaration/implementation of an SKScene? I have tried with little success.
//Current Implementation
class OldScene: SKScene {
var node1 = SKSpriteNode(imageNamed: "who cares")
var node2 = SKSpriteNode(imageNamed: "doesn't matter")
var node3 = SKSpriteNode(imageNamed: "this is instantiated")
var nodeVector: [SKSpriteNode] = [node1, node2, node3]
var timesWhenSomethingHappensToEachNode: [CGFloat] = [CGFloat(1.2), CGFloat(1.7), CGFloat(3.1)]
var framesUntilThisOccurs: [Int] = [2, 30, 15]
}
//Desired implementation
extension SKSpriteNode {
//timesWhenSomethingHappensToEachNode and framesUntilThisOccurs are made properties
//of SKSpriteNode
//probably happens in here
}
class NewScene: SKScene {
//Can we instantiate those extended types here?
var newNode1 = SKSpriteNode(imageNamed: "who cares")
var newNode3 = SKSpriteNode(imageNamed: "this is instantiated")
var nodeOneTime = newNode1.timesWhenSomethingHappensToEachNode
var framesUntilThreeHappens = newNode3.framesUntilThisOccurs
}