我在这个网站上搜索了如何来回旋转图像,并在这个网站上的其他帖子的帮助下想出了我自己的,它工作得很好,唯一的问题是现在我让它工作了,所以它旋转回来了按照我喜欢的方式,我现在怎么把它放在屏幕上?继承人到目前为止的代码:
private Bitmap ray;
private int mRot = -33;
private boolean goRight = true;
void onRotDraw(Canvas canvas)
{
int width = ray.getWidth();
int height = ray.getHeight();
if (mRot > 30){
goRight = false;
}
if (mRot < -30){
goRight = true;
}
if (goRight){
mRot += 1;
}else
{
mRot -= 1;
}
canvas.rotate(mRot,width / 2,height / 2);
this.Draw_Sprite(canvas, 0, mRot );
}
public void Draw_Sprite(Canvas c, int whatever, int rot) {
//rotating image back and forth
int width = ray.getWidth();
int height = ray.getHeight();
Rect src = new Rect(width - width, height - height, width, height);
Rect dst = new Rect(width - width, height - height, width, height);
c.drawBitmap(this.ray, src, dst, null);
}
通常使用 drawBitmap 我使用它来定位我的图像,但是这个使用 src 和 dst 而不是矩形的大小,所以现在它工作得很好但是我如何将屏幕上的位置从 0,0 更改为我想要的位置去吗?
这部分或大部分取自这篇文章: Sprite Rotation in Android using Canvas.DrawBitmap。我很接近,我做错了什么?
除了如何在屏幕上设置 x 和 y 位置之外,这给了我完成这一切所需的一切,对此的任何帮助将不胜感激,我一直在努力寻找一种方法来获得这个设置x 和 y 位置没有运气,它可能很简单。提前致谢。