zoukankan      html  css  js  c++  java
  • android第三天早:游戏画图基础

    视频:善知堂Android   http://www.verycd.com/topics/2915940/

    第三季

    第一集:游戏演示和理念

    用photoshop 其实也不难。

    第二集 绘图1

    1.在配置中加入命名空间

    xmlns:android="http://schemas.android.com/apk/res/android"

    2.设置button的属性

    //设置文本颜色
    button.setTextColor(Color.RED);

    3.将button上画圆形

    class MyButton extends Button {
    
            // 这个是继承必须写的,带参构造器,所以要重写
            public MyButton(Context context) {
                super(context);
                // TODO Auto-generated constructor stub
            }
    
            // 在按钮中画图
            @Override
            protected void onDraw(Canvas canvas) {
                // TODO Auto-generated method stub
                super.onDraw(canvas);
                // 画笔
                Paint paint = new Paint();
                paint.setColor(Color.GREEN);
                canvas.drawCircle(30, 30, 30, paint);
            }
    
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            MyButton my = new MyButton(this);
            LinearLayout lay = new LinearLayout(this);
            lay.addView(my);
            setContentView(lay);
    
        }

    4.使用画图写游戏的建议继承View

    class GameView extends View {
    
            private Paint paint = null;
    
            public GameView(Context context) {
                super(context);
                paint = new Paint();
            }
    
            @Override
            protected void onDraw(Canvas canvas) {
                // TODO Auto-generated method stub
                super.onDraw(canvas);
                paint.setColor(Color.RED);
                paint.setStrokeWidth(5);//画笔粗
                canvas.drawLine(0, 0, 100, 111, paint);
    
            }
    
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            GameView my = new GameView(this);
            LinearLayout lay = new LinearLayout(this);
            lay.addView(my);
            setContentView(lay);
    
        }

    第三天早 结束

  • 相关阅读:
    Shell while循环
    Shell for循环
    针对各主流数据mysql、sqlserver、oracle中文乱码问题。
    robots.txt网站爬虫文件设置
    MySql数据类型
    重温国产thinkphp
    CI分支kohana在线文档
    JIRA官方:为什么要用JIRA?
    百度地图V2.0实践项目开发工具类bmap.util.js V1.4
    Eclipse被汉化后恢复EN模式
  • 原文地址:https://www.cnblogs.com/wanself/p/2575577.html
Copyright © 2011-2022 走看看