I am making a Swift game with a lot of levels. Each level is in a file with sequential names:
Level1.swift
Level2.swift
Level3.swift
...
And each file has one class in it, and the class name matches the file name.
The reason that everything is a class is because all classes use similar functions from the base class, and also because of the large number of common variables.
The problem is that I donβt know how to load a level, just using an integer without doing this kind of disaster:
switch Int(level)! {
case 1:
newScene = Level1(size: frame.size)
case 2:
newScene = Level2(size: frame.size)
case 3:
newScene = Level3(size: frame.size)
...
SKScene(fileNamed:), - .sks, . , , , - Bundle.main.url - . , . .