2017-5-24实训的第十天!
来源:互联网 发布:十本法术工厂升级数据 编辑:程序博客网 时间:2024/06/05 09:40
飞机大战(菜单页面)
ヾ(Ő∀Ő๑)ノ太好惹 今天终于开始Android Studio的学习了
(눈‸눈) 虽然我还是学的脑里一团浆糊
GameSurface
public class GameSurface extends SurfaceView implements SurfaceHolder.Callback{private SurfaceHolder surfaceHolder;private Canvas canvas;private Paint paint;public static int screenWidth;public static int screenHeight; // Menu相关//菜单类所需的图片private GameMenu gameMenu;private Bitmap bmpMenuBG;//菜单页面背景图片private Bitmap bmpLogo;//菜单页面logoprivate Bitmap bmpButton;//菜单页面Buttonprivate Bitmap bmpText;//菜单页面文本public GameSurface(Context context){ super(context); surfaceHolder=this.getHolder(); surfaceHolder.addCallback(this); paint=new Paint(); paint.setAntiAlias(true);}@Overridepublic void surfaceCreated(SurfaceHolder holder) { screenWidth=this.getWidth(); screenHeight=this.getHeight(); initBitmap(); new Thread(new Runnable() { @Override public void run() { while (true) { myDraw(); } } }).start();}@Overridepublic void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}@Overridepublic void surfaceDestroyed(SurfaceHolder holder) {}private void myDraw() { canvas =surfaceHolder.lockCanvas(); // 调用GameMenu对象画游戏菜单页面 gameMenu.draw(canvas,paint); if (canvas!=null){ surfaceHolder.unlockCanvasAndPost(canvas); } } // 初始化图片方法 private void initBitmap() { //把图片转换成Bitmap格式 bmpMenuBG=BitmapFactory.decodeResource( this.getResources(),R.drawable.mainmenu); bmpLogo=BitmapFactory.decodeResource( this.getResources(),R.drawable.logo); bmpButton=BitmapFactory.decodeResource( this.getResources(),R.drawable.menustart); bmpText=BitmapFactory.decodeResource( this.getResources(),R.drawable.starttext); //初始化对象 gameMenu = new GameMenu(bmpMenuBG, bmpLogo, bmpButton, bmpText); } }
GameMenu
public class GameMenu { private Bitmap bmpMenuBG; private Bitmap bmpLogo; private Bitmap bmpButton; private Bitmap bmpText; private Rect rect; public GameMenu(Bitmap bmpMenuBG,Bitmap bmpLogo,Bitmap bmpButton,Bitmap bmpText){ this.bmpMenuBG=bmpMenuBG; this.bmpLogo=bmpLogo; this.bmpButton=bmpButton; this.bmpText=bmpText; rect = new Rect(0, GameSurface.screenHeight / 3, GameSurface.screenWidth, GameSurface.screenHeight / 3 + GameSurface.screenHeight / 5);}/** * 画菜单页面 * @param canvas * @param paint */public void draw(Canvas canvas,Paint paint){ // 画背景图 canvas.drawBitmap(bmpMenuBG,0,0,paint); canvas.drawBitmap(bmpLogo,null,rect,paint); int x=GameSurface.screenWidth/2-bmpButton.getWidth()/2; int y=GameSurface.screenHeight/3*2; canvas.drawBitmap(bmpButton,x,y,paint); int z=GameSurface.screenWidth/2-bmpButton.getWidth()/3; int s=GameSurface.screenHeight/3*2+20; canvas.drawBitmap(bmpText,z,s,paint); } }
MainActivity
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new GameSurface(this)); } }
铛铛铛٩(๑^o^๑)۶完成是这样哒!
阅读全文
1 0
- 2017-5-24实训的第十天!
- 实训第十天
- MiniDB实训第十天
- qt 实训第十天
- 实训笔记第十天
- 离去的第十天
- 学习的第十天
- 新年的第十天
- java实训第十天8/07
- 实训第十一天
- 实训第十一天
- 实训第十三天
- 实训第十五天
- 第十天 挑战性的一天
- 黑马程序员的第十天
- 学习C的第十天
- MiniDB实训第十一天
- MiniDB实训第十三天
- Oracle 分布式锁 kill 锁表进程
- unity3D 关于重新载入场景后Easytouch不能使用的问题
- 深入理解Spring Redis的使用 (二)、RedisTemplate事务支持、序列化
- php笔记
- oracle 全文索引
- 2017-5-24实训的第十天!
- 4880: [Lydsy2017年5月月赛]排名的战争
- MySQL主从复制
- 挑战程序竞赛系列(8):2.1一往直前!贪心法(其他)
- js中的3种弹出式消息提醒(警告窗口,确认窗口,信息输入窗口)的命令是什么?
- Oracle查询语句简单回顾(三)
- Java语法基础看这篇就够了
- 常用设计模式
- iOS中代理、通知、block的使用