在旋转的Andr​​oid有关的一个点位图不看动画 [英] Rotate a bitmap in android about a point without animation of view

查看:81
本文介绍了在旋转的Andr​​oid有关的一个点位图不看动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些很好的资源,这里elsewher在android的旋转位图国贸网。我靠近让我的code工作,但显然我不完全了解矩阵翻译工作。以下是我的精灵类三大功能。之前,我加的东西,方便矩阵旋转他们的工作很大(即在OnDraw中我打电话只用X,Y和没有矩阵抽奖)。我写了一些测试code添加一个精灵,并且从0到360,并返回到0旋转重复一次。它导致它绕像它的轨道一些奇怪的问题。在现实中,我希望它只是坐在那里,旋:

I found some good resources for rotating a bitmap in android here and elsewher eon the net. I am close to getting my code to work but apparently I don't fully understand how the Matrix Translations work. The following is three main functions from my sprite class. THey worked great before I added things to facilitate the matrix rotation (namely in the onDraw I called the draw with just x,y and no matrix). I wrote some test code to add a sprite, and rotate it from 0 to 360 and back to 0 again repeatedly. It results it in rotating about like its orbiting some odd point. In reality I want it to just sit there and spin:

public void Rotate_Sprite(int transform, int deg)
    {
        int spriteCenterX = x+(width/2);
                int spriteCenterY = y+(height/2);
        mMatrix.setRotate(deg, spriteCenterX, spriteCenterY);
        }

public void Draw_Sprite(Canvas c) { 
//c.drawBitmap(images[curr_frame], x, y, null); //this worked great esp in move sprite
    c.drawBitmap(images[curr_frame], mMatrix, null);
}

public void Create_Sprite(blah blah) {

    ...
    ...
    mMatrix = new Matrix();
    mMatrix.reset();
}

public int Move_Sprite() {
    //with the matrix stuff, I assume I need a translate.  But it does't work right 
    //for me at all.
    int lastx=this.x;
    int lasty=this.y;
    this.x+=this.vx;
    this.y+=this.vy;
    mMatrix.postTranslate(lastX-x,lastY-y); //doesn't work at all
}

我没有找到这个 J2me的类似的参考这里。虽然它似乎有所有我的精灵我呼吁在轨道上旋转围绕一个点。

I did find this J2me like reference here. Though it seems to have all my sprites I call rotate on in orbit around one point.

推荐答案

试试这个:

mMatrix.setTranslate(objectX,objectY);
mMatrix.postRotate(Degrees, objectXcenter, objectYcenter);

基本上,你需要将位图转换为你首先想要的位置,将其设置在那里,然后转动n度围绕中心。

Basically, you need to translate your bitmap to the location you want it first, set it there, then rotate it N Degrees around its center.

这篇关于在旋转的Andr​​oid有关的一个点位图不看动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆