Monday, 20 May 2013

Accessing resources and variables from class to class (Java - best practices)

Accessing resources and variables from class to class (Java - best practices)

My game code is getting quite big now and I thought I should stop to 'tidy' things up a bit before continuing.
The major problem I have is that I'm reaching through classes to access variables and I've asked similar questions on various forums before but I still can't work out the best way to do this.
I have my Main class (Class name: MyGLRenderer) which contains my game loop and also has the rendering code - this class, also carries out a few other tasks.
I have a class which is used solely to load all of my resources (bitmaps etc) and create all of my game objects (quad sprites). (Class name: Resources).
And I have a class which Updates my game logic - (Class name: Logic).
Pseudo code
So, this is my setup (These are simplified code snippets) and these include pseudo code (with explanatory comments)
public class MyGLRenderer{

    Logic logic;
    various game object variables declared here;

    public MyGLRenderer{

    logic = new Logic(this, res);    //Create new logic object so I can access the update method to use in my gameloop

    }

    public void onDrawFrame{

    logic.upd

No comments:

Post a Comment