Do I need to pass Main?

I am looking at drawing things in other classes, do I have to pass Main, which extends sprite, to these classes in order to do so?

Ive currently got a tileRender class which contains this:

public function new(main:Main,passedPosition:Point){

tilesheetCanvas = new Sprite();


Seems like an odd and inefficient way of handlign this, is there a way to draw to the canvas directly?

I think you can just use Lib.current.stage?

class Main extends Sprite 
        //This could be a class that inherits sprite. 
        private var currentState: State;
        public function new() 
            this.currentState = new State();

class State extends Sprite {
 private var something: Sprite;
 public function new() {
   this.something = new Sprite();
   // Will be displayed from main.

edit: Hope this clears things up :stuck_out_tongue:

So make the new class I want to draw with extend sprite, then do addchild from main when creating it. I will try it out, thanks very much for the help.

Another quick question, can these child states also have child states?

1 Like

I’m pretty sure you can nest it as deep as you’d like :stuck_out_tongue: