WEB开发网
开发学院手机开发Android 开发 Android加速感应器开发平衡球代码解析 阅读

Android加速感应器开发平衡球代码解析

 2011-01-05 10:14:17 来源:本站整理   
核心提示: mSensorY = -event.values[1]; break; case Surface.ROTATION_270: mSensorX = event.values[1]; mSensorY = -event.values[0]; break; } mSensorTimeStamp = eve

           mSensorY = -event.values[1];
           break;
         case Surface.ROTATION_270:
           mSensorX = event.values[1];
           mSensorY = -event.values[0];
           break;
       }

     mSensorTimeStamp = event.timestamp;
       mCpuTimeStamp = System.nanoTime();
     }

   @Override
     protected void onDraw(Canvas canvas) { //主要的小球绘制

     canvas.drawBitmap(mWood, 0, 0, null); //先画出背景

     final ParticleSystem particleSystem = mParticleSystem;
       final long now = mSensorTimeStamp + (System.nanoTime() - mCpuTimeStamp);
       final float sx = mSensorX;
       final float sy = mSensorY;

     particleSystem.update(sx, sy, now);

     final float xc = mXOrigin;
       final float yc = mYOrigin;
       final float xs = mMetersToPixelsX;
       final float ys = mMetersToPixelsY;
       final Bitmap bitmap = mBitmap;
       final int count = particleSystem.getParticleCount();
       for (int i = 0; i < count; i++) {
         final float x = xc + particleSystem.getPosX(i) * xs;
         final float y = yc - particleSystem.getPosY(i) * ys;
         canvas.drawBitmap(bitmap, x, y, null);
       }

     invalidate();
     }

   @Override
     public void onAccuracyChanged(Sensor sensor, int accuracy) {
     }
   }
}

 整个例子可以在Android 2.3 SDK的Samples文件夹下找到,这个小铁球的例子可以帮助我们改造为平衡球游戏。

上一页  1 2 3 4 5 6 

Tags:Android 加速 感应器

编辑录入:coldstar [复制链接] [打 印]
赞助商链接