Iced Tea Labs Share to be shared

2D Graphics using Multi-threading

A - Introduction Multi-threading

To a game developer, Multi-threading is a must-know term.

Multi-threading is used when your application needs to do a lot tasks parallely. By this way, all the tasks will run parallely and don’t have to wait for the others finished.

B - 2D Graphics using Multi-threading Demo description

The application will draw a moving green ball on the screen.

When user tap on the ball when it’s moving, It’ll stop and vice versa.

In this demo, there’re 2 thread run parallely:

C - Demo implementation

Firstly, create GameView class:

As you can see, GameView is the screen where the “green ball” moving. GameView will also catch all the user interactions event.

Hence, we cannot let the GameView take responsibility for calculating and drawing the green ball –> We need to create a new Thread to handle it!


Create  GameThread class:

Finally, in MainActivity, call  setContentView(new GameView(this, null))

Enjoy the result:

D - Download Source Code

comments powered by Disqus