如果有人能给我一个关于如何计算屏幕每秒帧数的小代码,那就太好了。
这是我的基本代码,尽管您可能不需要它。
import java.util.Random;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
public class MainGame extends Activity implements OnTouchListener
{
MyBringBackSurface ourSurfaceView;
inr xpos = 0;
@ Override
protected void onCreate (Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate (savedInstanceState);
ourSurfaceView = new MyBringBackSurface (this);
ourSurfaceView.setOnTouchListener (this);
x [0] = 0;
y [0] = 0;
x [1] = 0;
y [1] = 0;
requestWindowFeature (Window.FEATURE_NO_TITLE);
getWindow ().addFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); /////////////////////check this NEWLY ADDED
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); /////////////////////////////////////////////////CHECK THIS MIGHT NOT WORK
setContentView (ourSurfaceView); //ourSurfaceView
}
@ Override
protected void onPause ()
{
// TODO Auto-generated method stub
super.onPause ();
ourSurfaceView.pause ();
}
@ Override
protected void onResume ()
{
// TODO Auto-generated method stub
super.onResume ();
ourSurfaceView.resume ();
}
public class MyBringBackSurface extends SurfaceView implements Runnable
{
//vertical
SurfaceHolder ourHolder;
Canvas canvas = (Canvas) ourHolder;
Thread ourThread = null;
boolean isRunning = false;
public MyBringBackSurface (Context context)
{
// TODO Auto-generated constructor stub
super (context);
ourHolder = getHolder ();
}
public void pause ()
{
isRunning = false;
while (true)
{
try
{
ourThread.join ();
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace ();
}
break;
}
ourThread = null;
}
public void resume ()
{
isRunning = true;
ourThread = new Thread (this);
ourThread.start ();
}
public void run ()
{
// TODO Auto-generated method stub
while (isRunning)
{
if (!ourHolder.getSurface ().isValid ())
continue;
canvas = ourHolder.lockCanvas ();
Paint paint = new Paint();
paint.setColor(Color.BLUE);
canvas.drawCircle(xpos,33,23,paint);
if(x<canvas.getWidth()){
xpos++;
}
ourHolder.unlockCanvasAndPost(canvas);
}
}
请给我一个简单的工作代码谢谢