Search code examples
iossprite-kitlevels

creating levels with same code in sprite kit game


I am making a sprite kit game, and I am kind of a beginner in iOS development. In my game, I am using 1 SKScene as 1 level. Each level will have increased difficulty from the previous level. By making multiple SKScenes, I have noticed that I have to reuse the code of previous levels again and again with minor changes to raise the difficulty. Isn't there a better way to do this rather than creating multiple scenes and copying the same code again and again? Is there a way to reuse the repeated code? If I want to create many levels, this would become cumbersome, and seems to reflect a bad design.


Solution

  • And thus the theory of object oriented programming came forth, in your case specially inheritance. OOP is specially used when we have to reuse a code over and over again, We just inherit the class and then we can call its methods in that subclass, or even overwrite or overload the methods according to our own will.

    Please check out documentations as to how inheritance takes place. In objective c u can inherit a class by

     @interface 
     yourclassName : superclassName  
    

    syntax