Building the GameObjectFactory

It is the job of the GameObjectFactory to use the ObjectSpec based classes to assemble GameObject instances with the correct components.

Create a new class called GameObjectFactory and add the following members and constructor shown next.

class GameObjectFactory {
    private Context mContext;
    private PointF mScreenSize;
    private GameEngine mGameEngineReference;

    GameObjectFactory(Context c, PointF screenSize, 
                      GameEngine gameEngine) {
        
        this.mContext = c;
        this.mScreenSize = screenSize;
        mGameEngineReference = gameEngine;
    }
}

We have a Context object, a PointF to hold the screen resolution and a GameEngine object to hold a reference to the GameEngine class. In the constructor all these member variables are initialized. It is ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.