当我使用变量时,它被设置为0,为什么?

时间:2014-08-21 21:11:22

标签: android

当我使用变量gv.PanX和gv.PanY时,它们被重置为0为什么?

我使用它们的类(编辑它们):

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = ev.findPointerIndex(mActivePointerId);
            final float dx = x - mLastTouchX;
            final float dy = y - mLastTouchY;
            mPosX += dx;
            mPosY += dy;


        mLastTouchX = x;
        mLastTouchY = y;

        gv.PanX = (int)mPosX;
        gv.PanY = (int)mPosY;
        DragX = ev.getX(pointerIndex);
        DragY = ev.getY(pointerIndex);
        break;

    }

我在哪里阅读:

public void drawbitmapOnCanvas(String bmname, Bitmap bm, int X, int Y, SpriteBatcher sb){
    Log.v("touch", "drawing: " + gv.PanX + " : " + gv.PanY);
    int bmInt = getBitmapInt(bmname);
    int YPan = 0;
    int XPan = 0;

    Rect rec1 = new Rect(0, 0, bm.getWidth(), bm.getHeight());

    Rect rec2 = new Rect(XPan + X, YPan + Y, XPan + X + bm.getWidth(), YPan + Y + bm.getHeight());
    sb.draw(bmInt, rec1, rec2);
}

实际变量:

public class GlobVar {
public int PanX, PanY = 0;
}

和gv代表:

GlobVar gv = new GlobVar();

当我不使用vars并将它们发布到Log时它们工作正常但是当我尝试使用它们时它们再次变为0。 感谢所有看过这个的人;)

0 个答案:

没有答案