In the production of the game, the background can be moved, the principle is two pictures of the circular movement.
Package Com.example.manager;
Import COM.EXAMPLE.AGAME.R;
Import Com.example.entity.Enemy;
Import Android.graphics.Bitmap;
Import Android.graphics.BitmapFactory;
Import Android.graphics.Canvas;
Import Android.graphics.Rect;
Import Android.view.View;
public class backgroundmanager{
Private Bitmap Background=null;
Private Rect Secrect,desrect,desrect2;
private int dy1,dy2;
private int x, y;
Public Backgroundmanager (view view) {
X=view.getwidth ();
Y=view.getheight ();
Dy2=-view.getheight ();
Background=bitmapfactory.decoderesource (View.getresources (), r.drawable.background);
Secrect=new Rect (0,0,background.getwidth (), Background.getheight ());
Desrect=new Rect (0,dy1,x,y);
Desrect2=new Rect (0,dy2,x,y);
}
public void Drawbackground (canvas canvas) {
dy1+=3;
dy2+=3;
Desrect.set (0,DY1,X,Y+DY1);
Desrect2.set (0,DY2,X,Y+DY2);
Canvas.drawbitmap (background,secrect,desrect,null);//The first picture is in the center of the screen
Canvas.drawbitmap (background,secrect,desrect2,null);//The second picture is above the screen
if (dy1>=y)
dy1=-y+3;//For background connection harmony
if (dy2>=y)
dy2=-y+4;
}
}
This will enable the background loop to move!!!
This article is from the "Software Learning Summary" blog, be sure to keep this source http://bigcrab.blog.51cto.com/10626858/1685028
Android Aircraft War (i) Background movement