I've been reading about compartmentalizing functions to be used in a game, which I'm making (using entity component design). My question has to do with how to implement this.
This game makes use of multiple scenes. Across these scenes, I'm finding I've written code that is doing largely the same thing multiple times (e.g. a code to animate a character).
So I see something like this:
func animateCharacter() {
}
...multiple times across various files associated with each scene.
What is the correct way to write a function once within a scene, and then share it across the other scenes? Is there some way of doing this?
It turns out that this problem was sorted when I implemented GameKit correctly (e.g. using one view controller across multiple scenes). Someone in an earlier comment helped me do this, after which time I made all other scenes subclasses of an initial scene, and used the function in the original class.