Author Topic: Why is a Class (not instance) passed to FlxGame?  (Read 1004 times)


  • Member
  • **
  • Posts: 35
  • Karma: +0/-0
    • View Profile
Is there a reason that in the initial constructor of "FlxGame" you pass a "Class", but in "FlxG.switchState()" you pass an instance? Is this an oversight, or is there a good reason for that?

Personally, I would prefer if an instance is passed as you can pass starting values along to the constructor of the FlxState.

And if someone really stubbornly wants to pass a class, perhaps that parameter could be untyped allowing either a class or instance?

I wasn't sure if this was a question for the GitHub issue tracker, or if that's reserved for bugs. In fact, is there any place where the contributors have written out the logic behind various decisions of how they structured Flixel (more than what can be found scattered about in the code comments)?


  • Active Member
  • ***
  • Posts: 131
  • Karma: +0/-0
    • View Profile
Re: Why is a Class (not instance) passed to FlxGame?
« Reply #1 on: Thu, Dec 22, 2011 »
I just looked around the code, it seems like it has to create an instance of it by itsself for first-initialization and/or something about resetting the game. But yeah I don't approve it very much. If you really want to pass values to constructor, just make a dummy state, give it to FlxGame constructor. Then switch state in that dummy state by creating the state you want with constructor.