I'm working on my first Android project - Live wallpaper. I need some images in my project to fly all the time on the screen. Images should fly from bottom to top, but they need to fly all time, so that background is never empty. This is part of my code but I know that I need more than that.
void draw(Canvas c) {
c.save();
c.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.wallpaper1), 0, 0, null);
double tmp = Math.sin(fiX * Math.PI / 180F) * 20;
Bitmap bm = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.heart_s);
c.drawBitmap(bm, 100 + (int) tmp, posY, paint);
double tmp1 = Math.sin(fiX * Math.PI / 180F) * 20;
Bitmap bm1 = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.heart1);
c.drawBitmap(bm1, 300 + (int) tmp1, posY, paint);
double tmp2 = Math.sin(fiX * Math.PI / 180F) * 20;
Bitmap bm2 = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.heart3);
c.drawBitmap(bm2, 200 + (int) tmp2, posY, paint)
posY = posY -direction;
fiX = fiX + 10;
if(posY < 0) {
//posY = getResources().getDisplayMetrics().heightPixels;
direction = 5;
}
if(posY > getResources().getDisplayMetrics().heightPixels) {
direction = 5;
}
if(fiX > 180) {
fiX = 0;
}
c.restore();
}