@Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.RED); paint.setTextSize(40); /* * draw the background */ canvas.drawBitmap(mPool, 0, 0, null); /* * compute the new position of our object, based on accelerometer * data and present time. */ 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; String scor = "score: " + score.toString(); // canvas.rotate(90); canvas.drawText(scor, xc, yc, paint); int i = 0; for (Particle p : particleSystem.mBalls) { /* * We transform the canvas so that the coordinate system matches * the sensors coordinate system with the origin in the center * of the screen and the unit is the meter. */ i++; final float x = xc + particleSystem.getPosX(i) * xs; final float y = yc - particleSystem.getPosY(i) * ys; canvas.drawBitmap(p.bitmap, x, y, null); } // and make sure to redraw asap invalidate(); }
@Override protected void onDraw(Canvas canvas) { /* * draw the background */ // canvas.drawBitmap(mWood, 0, 0, null); /* * compute the new position of our object, based on accelerometer * data and present time. */ 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++) { /* * We transform the canvas so that the coordinate system matches * the sensors coordinate system with the origin in the center * of the screen and the unit is the meter. */ final float x = xc + particleSystem.getPosX(i) * xs; final float y = yc - particleSystem.getPosY(i) * ys; canvas.drawBitmap(bitmap, x, y, mPaint); } // and make sure to redraw asap invalidate(); }