samedi 28 février 2015

Multi layer parallax live wallpaper


I'm just starting android programming, and I'm trying to make a live wallpaper with multiple images and a parallax effect. I load the bitmaps at startup.


This is my code for offset changed:



@Override
public void onOffsetsChanged(float xOffset, float yOffset,
float xStep, float yStep, int xPixels, int yPixels)
{
this.mmPixel= (float) (xPixels * 0.8);
this.mmPixel1= (float) (xPixels * 1);
this.mmPixel2 = (float) (xPixels * 1.2);
this.mmPixel3 = (float) (xPixels * 1.5);
drawFrame();
}


and this is my code for the drawFrame:



void drawFrame()
{
if(!mVisible) return;
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try
{
c = holder.lockCanvas();
if(c != null)
{
c.drawBitmap(background, mmPixel, 0, paint);
c.drawBitmap(layer1, mmPixel1, 0 , paint);
c.drawBitmap(layer2, mmPixel1, 0, paint);
c.drawBitmap(layer3, mmPixel2, 0, paint);
}
}finally
{
if(c != null) holder.unlockCanvasAndPost(c);
}

mHandler.removeCallbacks(mDrawScene);
if(mVisible)
{
mHandler.postDelayed(mDrawScene, 1000/30);
}
}


The problem that I'm running into is that I encounter serious lag with even 720p images. This is a problem when the phone I'm testing on has a 720p screen, and I want to develop for full HD screens and beyond. Is there any way to make this run faster or more efficiently?





Aucun commentaire:

Enregistrer un commentaire