As the title of the tutorial suggests we will be using interfaces. Interfaces are a special type of class and we already know how to create classes. However, we will not be creating any of our own interfaces until we get to the level two tutorials. There is no need, we can still make some really cool games without doing so but we will use interfaces that have been created for us as they can bring complex functionality to our games with great ease.

  • The courses above are up to 95% off - only $19 using voucher code APRUDEMY17. Limited time offer.


An interface is a class which has no method implementations. This might sound a bit odd but one of the things this achieves is to provide us with the ability to override these methods in our code. This is especially helpful as these methods are called by the operating system at events that are useful to us.

We saw something similar in our thread tutorial. We overrode the run method by using the @override keyword. When we do this we can be sure that our code, enclosed in the run method, as well as any other methods we call from this method, (like update and draw)  will work in the thread.

Interfaces can also provide critical functionality like allowing us to interact with the user’s input. For example, for Android, all we need to do is use the onTouchListener interface and we can then @override the onTouchEvent method. Then, every time the player touches the screen we can deal with it, according to the needs of our game. Just like this.

@Override
public boolean onTouchEvent(MotionEvent motionEvent) {

	// Handle the player input here

}

Note that the method and interface names are different when dealing with desktop Java but the concept is identical.

The final explanation that is necessary before we build a game is that in Java everything is a class or part of a class. Our game is no exception. You will have seen this already if you completed any of the mini projects associated with earlier tutorials. When we declare our class all we have to do is add the implements keyword followed by the name of the interface or interfaces we want to use.

Let’s put into action and clarify everything we have learned in the previous 10 tutorials and build a simple game engine.

  • The courses above are up to 95% off - only $19 using voucher code APRUDEMY17. Limited time offer.