hi,
i am trying to create two spinning wheels, as in pulleys, so everytime
the attached rope moves, the two pulleys will rotate. i have tried
two approaches:
1) use Matrix.postRotate within the onDraw() method of the View class,
which calls the following:
private void drawSpinningWheel(Canvas canvas)
{
try
{
canvas.save();
Bitmap bitmapOrg = null;
int iDrawable = R.drawable.spinning_button;
bitmapOrg = BitmapFactory.decodeResource(getResources(),
iDrawable);
if(bitmapOrg != null)
{
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 24;
int newHeight = 24;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// createa matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate((float) mDegrees++);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg,
0, 0,
width, height, matrix, true);
canvas.drawBitmap(resizedBitmap, matrix, null);
}
canvas.restore();
}
catch(Exception e)
{
Log.e(TAG + "drawSpinningWheel", e.getMessage());
}
}
but it seems like the image not only spins but rotates around another
axis
2) use SurfaceView and a separate thread, in the run() call this:
private void doDraw(Canvas canvas) {
// Draw the background image. Operations on the Canvas
accumulate
// so this is like clearing the screen.
canvas.drawBitmap(mBackgroundImage, 0, 0, null);
int yTop = mCanvasHeight - ((int) mY +
mSpinningWheelImageHeight / 2);
int xLeft = (int) mX - mSpinningWheelImageWidth / 2;
...
// Draw the ship with its current rotation
canvas.save();
canvas.rotate((float) mHeading++, (float) mX,
mCanvasHeight
- (float) mY);
mSpinningWheelImage.setBounds(xLeft, yTop, xLeft +
mSpinningWheelImageWidth, yTop
+ mSpinningWheelImageHeight);
mSpinningWheelImage.draw(canvas);
canvas.restore();
}
i get the spinning to work but i can't add another spinning wheel. i
even tried to create another thread for the second spinning wheel,
only one shows up. can someone point me in the right direction?
thanks.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe, reply using "remove me" as the subject.