I'm creating a live wallpaper with parallax scrolling. I've read the article: Parallax effect scrolling of live wallpaper background. But when I change desktops the background moves wrong way (If I change desktop from left to right, picture moves from right to left). How to change direction? Code snippet:
public void Init(Bitmap bitmap){
bg = new BitmapFactory().decodeResource(context.getResources(), R.drawable.thunder);
bg = Bitmap.createScaledBitmap(bg, (int)(width*1.4), height, true);
}
float dx = 0.0f;
@Override
public void onOffsetsChanged(float xOffset, float yOffset,
float xStep, float yStep, int xPixels, int yPixels) {
dx = (width - bg.getWidth()) * (1 - xOffset);
}
private void doDraw(Canvas canvas) {
canvas.save();
canvas.translate(dx, 0);
canvas.drawBitmap(bg, 0, 0, null);
canvas.restore();
}