我正在制作游戏,并且有一堆向量,每个索引对应于另一个向量中的SKSpriteNode。你可以扩展SKSpriteNode类以包含我在相应索引中存储在其他向量中的属性,然后在SKScene的类声明/实现中创建类型为ExtendedSKSpriteNode的对象吗?我尝试了一点点成功。
//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
}