MG_MG
(Miguel)
1
Hi there:
I'm trying to order my program by putting functions in different files. I've tried with class files, but I run into the following problem:
-When functions where using self.something, it gives an error (it's clear: they are not in the same place anymore).
-When they require components from the main class, I don't have them
-It can't access to the main class features
As an example, I'm trying to access things like view.background from the main class, but no matter how I try, they don't work (the rest, simple functions, do).
If you want to define some functionality for a class in a different file relative to its declaration, you will have to use an extension. Can you provide some code that illustrates the problem you are running into?
MG_MG
(Miguel)
3
Let's say in GameScene.swift file I have a class like this
class GameScene: SKScene {
And from another class in a differenf file:
class backgroundActions: SKSpriteNode {
I want to perform a:
func move(){
scene?.addChild(sprite)_
scene?.backgroundColor = UIColor.green _
}
Regarding the previous one, with something like:
backgroundActions.move()