Since I am new to swift and spriteKit, I have read the document from apple:
I tried to load some images like this code below:
let textureArray = [SKTexture(imageNamed: "enemy1"),SKTexture(imageNamed: "enemy2"),SKTexture(imageNamed: "enemy3")]
override func viewDidLoad() {
super.viewDidLoad()
SKTexture.preload(textureArray) {
if let view = self.view as! SKView? {
// Load the SKScene from 'GameScene.sks'
if let scene = SKScene(fileNamed: "GameScene") {
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Present the scene
view.presentScene(scene)
}
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
}
}
}
Now, my question is how to use the textures I have loaded? For example, in another swift file, I have a class called player, how could I use the textures I have loaded to crate a SkspriteNode? How to pass the textureArray to that class?