Some optimizations and improvements

We will do some optimizations to our game by shifting our mainThread after our surface has been created. So, we will remove mainThread = new MainGameThread(getHolder(), this); from our constructor and write it just above the place where we start running it in our surfaceCreated() method, as follows:

@Overridepublic void surfaceCreated(SurfaceHolder holder){    bgImg = new BackgroundImage(BitmapFactory.decodeResource    (getResources(), R.drawable.background_image));    playerCharacter = new PlayerCharacter(BitmapFactory.decodeResource    (getResources(),R.drawable.player_run),200,246,3);    rocks = new ArrayList<Rock>();    upperBoundary = new ArrayList<UpperBoundary>();    lowerBoundary = new ArrayList<LowerBoundary>();

Get Learning Android Game Development 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.