Best game structure to work with in SpriteKit

In unity when you create a new class, that class gets access to all the universal scene functions such as Update, Start, Awake, so for example if you want to create an Enemy class you can code everything regarding that object in jus tone class like what it's position when the scene loads, what it supposed to do in the update function and what other objects it should collide with, but is Spritekit when yo ucreate an Enemy class ( not to mention all the frustrating initializers) you again must create an instance of it in the scene class, position it and make different conditions for collisions. also if there are conditions for the touch status you need to define it in the Scene and not in it's class, but let's say you did all that and coded all the behaviours in the scene, what would you do when you have multiple scenes, aka game with multiple levels ? I'm also wondering Why the "Update" function only available in SKScene ?!


Bottom line what is the best gaming structure one can create in order to have flexibility in expanding the game and avoid repeating himself ?

This is a really good question, and highlights one of the very (few) great things about Unity.


The truly modular nature of the Entity/Component/Script relationships in Unity is fantastic.


When I first read about the game loop methods within SceneKit and SpriteKit I thought Apple had done the world a favour and given us something similar.


But it's not.


Someone with more expertise in describing how these game loops and inter-object communication works - want to chime in and answer the question?


Please!!!


I've just poked around in the documentation, it is horrid. It's documentation in the lowest sense of the word. Not educational material, that's for sure. As reference material it's a mess, too.

One possible solution to the "update only in scene" problem. Have an array in your main game scene. When you create a node interested in getting updates, add it to this array. Implement update method in the node subclass the same way you would in the scene. In your scene's update method, loop through the interested node array and call update on each of those nodes in turn. You may have to sort the array if you need them called in a certain order though.


Also, there is the SKSceneDelegate protocol. If you want the same behavior for multiple scenes, you could make a GameManager class (or call it whatever), assign it as the current scene's delegate, and then have that class farm out update calls to interested nodes. The delegate will override (if present) all the same calls the scene would normally get: update, didSimulatePhysics, etc., and the scene that's delegating is passed as a parameter into each of these methods.

Best game structure to work with in SpriteKit
 
 
Q