Android粒子效果

您所在的位置:网站首页 surfaceChanged Android粒子效果

Android粒子效果

2023-06-16 21:02| 来源: 网络整理| 查看: 265

ActivityMain.java

 

[java] view plaincopy public class DrawThread extends Thread {       ParticleView pv;       SurfaceHolder suraceHolder;       boolean isRunning;       int sleepSpan = 15;       long start = System.nanoTime();       int count = 0;       public DrawThread(ParticleView pv, SurfaceHolder suraceHolder) {           this.isRunning = true;           this.pv = pv;           this.suraceHolder = suraceHolder;       }          @Override       public void run() {           Canvas canvas = null;           while(isRunning){               try{                   canvas = suraceHolder.lockCanvas();                   synchronized(suraceHolder){                       pv.doDraw(canvas);                   }               }catch(Exception e){                   e.printStackTrace();               }finally{                   if(canvas!=null){                       suraceHolder.unlockCanvasAndPost(canvas);                   }               }               this.count++;               if(count == 20){                   count = 0;                   long tempStamp = System.nanoTime(); //获取当前时间                   long span = tempStamp - start;      //获取时间间隔                   start = tempStamp;                  //为start重新赋值                   double fps = Math.round(100000000000.0/span*20)/100.0;//计算帧速率                   pv.fps = "FPS:"+fps;//将计算出的帧速率设置到BallView的相应字符串对象中                                  }               try{                   Thread.sleep(sleepSpan);//线程休眠一段时间               }               catch(Exception e){                   e.printStackTrace();//捕获并打印异常               }           }       }      }  

 

DrawThread.java

 

[java] view plaincopy public class ActivityMain extends Activity {       /** Called when the activity is first created. */       @Override       public void onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);           requestWindowFeature(Window.FEATURE_NO_TITLE);      //不显示标题           getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                    WindowManager.LayoutParams.FLAG_FULLSCREEN);           ParticleView lz = new ParticleView(this);           setContentView(lz);       }   }  

 

Particle.java

 

[java] view plaincopy public class Particle {       int color;          //粒子颜色       int r;              //粒子半径       double ver_v;       //垂直速度       double hor_v;       //水平速度       int startX;         //初始X坐标       int startY;         //初始Y坐标       int x;              //实时X坐标       int y;              //实时Y坐标       double startTime;   //起始时间              public Particle(int color, int r, double ver_v, double hor_v, int x, int y, double startTime) {           super();           this.color = color;           this.r = r;           this.ver_v = ver_v;           this.hor_v = hor_v;           this.startX = x;           this.startY = y;           this.x = x;           this.y = y;           this.startTime = startTime;       }   }  

 

ParticleSet.java

 

[java] view plaincopy public class ParticleSet {       ArrayList particleSet;       public ParticleSet(){           particleSet = new ArrayList();       }              public void addParticle(int count,double startTime){           for(int i=0;i


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3