3

我是新手,这是我的第一个 android 项目,我似乎无法找到如何让 Bitmap 为我工作。我真的需要这段代码我不知道如何设置偏移量变化我需要一些帮助。

这是我的代码示例

@Override
public void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
}

@Override
public Engine onCreateEngine() {
    // TODO Auto-generated method stub
    return new SwerveEngine();
}

// ===============================================
// ===============================================

public class SwerveEngine extends Engine implements Runnable {

    float mOffset;
    float xOffset = -480; 
    float yOffset ;
    float xOffsetStep = -240 ;
    float yOffsetStep ; 
    float xPixelOffset = - 480;
    float yPixelOffset ;

    float y = -1;
    float x = -240;
    float mX = -1;
    float mY = -1;
    int dx = 2;
    int dy = 2;
    int radius = 1;

    double gravity = 15;
    double energyloss = .65;
    double dt = .2;

    Bitmap done, bg;

    // private int xOffset;

    public SwerveEngine() {
        // TODO Auto-generated constructor stub
        done = BitmapFactory.decodeResource(getResources(),
                R.drawable.smalllaker);
        bg = BitmapFactory.decodeResource(getResources(),
                R.drawable.lakerpt2);

        // float x = -1*(int)((xOffset*done.getWidth()));
    }

    @Override
    public void onVisibilityChanged(boolean visible) {
    }

    @Override
    public void onCreate(SurfaceHolder surfaceHolder) {
        // TODO Auto-generated method stub
        super.onCreate(surfaceHolder);
    }

    @Override
    public void onOffsetsChanged(float xOffset, float yOffset,
            float xOffsetStep, float yOffsetStep, int xPixelOffset,
            int yPixelOffset) {

        super.onOffsetsChanged(xOffset, yOffset,
                xOffsetStep, yOffsetStep, xPixelOffset, yPixelOffset);

        mOffset = xPixelOffset;
        drawFrame();
    }

    public void setWallpaperOffsetSteps(float xStep, float yStep) {

    }

    @Override
    public void onSurfaceChanged(SurfaceHolder holder, int format,
            int width, int height) {
        // TODO Auto-generated method stub
        super.onSurfaceChanged(holder, format, width, height);

    }

    void drawFrame() {
        final SurfaceHolder holder = getSurfaceHolder();

        Canvas c = null;
        try {
            c = holder.lockCanvas();
            if (c != null)


            c.drawBitmap(bg, mX, c.getHeight()/2, null);
            c.drawBitmap(done, 0, c.getHeight()/2 - 89, null);

        } finally {
            if (c != null)
                holder.unlockCanvasAndPost(c);
        }

    }

    // View arg0,
    public boolean onTouch(MotionEvent arg1) {
        // TODO Auto-generated method stub
        if (arg1.getAction() == MotionEvent.ACTION_MOVE) {
            mX = arg1.getX();
            mY = arg1.getY();
        } else {

            mX = -1;
            mY = -1;
        }

        super.onTouchEvent(arg1);
        return false;
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub

    }

}

@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
    // TODO Auto-generated method stub
    return false;
}

}

感谢您的帮助 !!

4

0 回答 0