Initializing our variables

After defining our variables, it is also essential to initialize them. We do so from 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>();    rockStartTime = System.nanoTime();    //we can safely start the game loop    mainThread.setRunning(true);     mainThread.start();}

And that takes care of our variable values.

Get Learning Android Game Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.