How to Use the Android platform to develop FPS games? What are the implementation methods and what are the differences between these methods? First, let's first understand what FPS is.
English name: FPS (First Personal Shooting)
The first-person perspective shooting game, as its name implies, is a shooting game from the player's subjective perspective. Players no longer manipulate virtual characters on the screen like other games, but experience the visual impact of the game in an immersive manner, which greatly enhances the initiative and realism of the game. Early first-person games generally bring exciting screen light and a simple and quick game pace to gamers. With the gradual improvement of game hardware and the continuous integration of various types of games. The first-person shooting game provides richer plots, exquisite pictures, and vivid sound effects. For example, the CS, Quake, UT, honors, Call of Duty, DOOM, Rainbow 6, killer 47, cross-line, Anti-Terrorism Online games we play.
01 private boolean drawall = false;
02 private RefreshHandler mRedrawHandler = new RefreshHandler ();
03 class RefreshHandler extends Handler {
04
05 @ Override
06 public void handleMessage (Message msg ){
07 KetrisCanvas. this. update ();
08 KetrisCanvas. this. invalidate ();
09}
10
11 public void sleep (long delayMillis ){
12 this. removeMessages (0 );
13 sendMessageDelayed (obtainMessage (0), delayMillis );
14}
15 };
16 long mLastMove = 0;
17 long mMoveDelay = 30;
18 public void update (){
19 long now = System. currentTimeMillis ();
20
21 if (now-mLastMove> mMoveDelay ){
22 // gameLogic (); here is the game logic
23
24 mLastMove = now;
25}
26 mRedrawHandler. sleep (mMoveDelay );
27
28}
29 public void onDraw (Canvas canvas)
30 {super. onDraw (canvas );
31 this. paint (); // this is drawn to the buffer Screen
32 canvas. drawBitmap (g. offs, 0, 0, g. p );
33}
2. [Code] [Java] Code jump to [1] [2] [full screen Preview]
View source print? 01 public class KetrisCanvas extends SurfaceView implements SurfaceHolder. Callback
02
03 {
04
05. Complete the following two statements in the constructor:
06 holder = this. getHolder (); // Get holder
07 holder. addCallback (this );
08
09
10 @ Override
11 public void surfaceChanged (SurfaceHolder holder, int format, int width,
12 int height ){
13 // TODO Auto-generated method stub
14
15}
16
17 Thread t;
18 boolean isrun = true;
19 final SurfaceHolder holder;
20 @ Override
21 public void surfaceCreated (SurfaceHolder holder ){
22 // TODO Auto-generated method stub
23
24 t = new Thread (){
25 public void run ()
26 {while (isrun)
27 {
28 long start = System. currentTimeMillis ();
29 Canvas canvas = KetrisCanvas. this. holder. lockCanvas (null );
30 // complete the game logic here
31
32 paint (); // the screen is drawn here
33 canvas. drawBitmap (g. offs, 0, 0, null );
34
35 KetrisCanvas. this. holder. unlockCanvasAndPost (canvas );
36 long end = System. currentTimeMillis ();
37 if (200> end-start)
38 {
39 try {Thread. sleep (200-(end-start);} catch (Exception e ){}
40}
41}
42}
43 };
44 t. start ();
45}
46 @ Override
47 public void surfaceDestroyed (SurfaceHolder holder ){
48 // TODO Auto-generated method stub
49 if (t! = Null)
50 {isrun = false;
51}
52}