Search code examples
javalibgdx

libgdx structure of code


I have a general question about how I should organize my classes. I'm still beginning to learn to work with libgdx. For my test games now I always used screens and inside those screen a stage. For example the PlayScreen had a stage in it with all the actors in my game. 1) Is this a good way to organize or should I do it differently? 2) My UI was always in the screen class and not in the Stage class, is this right or should it be in the stage class? I drew sprites of my actors always in the screen class. I have a separate class, for example PlayerDraw, that draws the texture on the player. 3) Should I do this in the actor class of the player itself? I hope my questions aren't too vague.

Thanks in advance


Solution

  • LibGDX should be structured the same as in any language. If that Screen class is getting too big and unreadable you should transfer code to a new class. Your code must stay readable and reusable. So small documented classes and methods are priority. Other then that whatever works works.

    If your game UI code does not take more then a couple lines of code then leave it in that screen class. If it takes more just take it out. I usually start questioning the class if it starts to outgrow 200 lines of fairly compact code. You can always have exceptions off course.