绘制包含图像的圆圈网格

时间:2014-03-25 09:21:52

标签: android bitmap android-canvas drawable

目前我正在尝试在Android中制作游戏。我是android的新手,所以我想向你们学习。我的游戏主题几乎就像这个https://play.google.com/store/apps/details?id=com.pixelcrater.SmartDots。我设计了一个包含四个选项的开始屏幕,"单人播放器"," 2播放器","帮助"和"退出"。当玩家点击单人游戏或双击时,棋盘应该出现包含网格点。这些点将一直存在,直到玩家在它们之间点击以显示一条线。 现在问题在于董事会。我已经定义了一个2D圆阵列,以在这些圆圈中显示点(.png)。 现在我正试着打电话给"黑点"来自我圈子里的res文件夹。但我还没有找到满足我要求的网络帮助。我在下面提到我的代码。请建议我应该怎么做才能在圈子中显示图像。我的代码正确执行并显示(5 * 6)黑色背景的圆圈网格。现在我需要的是在这些圈子中的res文件夹中显示.png黑点。 这是我的代码文件。

package com.example.circle;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new board(this));
    }
    public class board extends View
    {
        Paint p = new Paint();
        Paint blue=new Paint();
        // Paint green=new Paint();
        int rows=5;
        int cols=6;
        Bitmap [][] dot=new Bitmap[rows][cols];
        Canvas g=new Canvas();
        public board(Context context) {
            super(context);
            p.setARGB(255, 255, 102,0);
            blue.setARGB(255, 255, 255, 255);
            // green.setARGB(0, 0, 06, 0);
            for(int y=0; y<cols; y++)
            {
                for(int x=0; x<rows; x++)
                {
                    Bitmap grid= Bitmap.createBitmap(100,100, Config.RGB_565 );

                    dot[x][y]=grid;
                    g.setBitmap(dot[x][y]);
                    g.drawCircle(50, 50, 20, blue);

                }
            }
        }
        protected void onDraw(Canvas canvas)
        {
            super.onDraw(canvas);
            canvas.drawPaint(p);
            for(int y=0; y<cols; y++)
            {
                for(int x=0; x<rows; x++)
                {
                    //g.drawCircle(50, 50, 20, blue);
                    //canvas.drawCircle(50, (x + 1) * 2 * 50, (y + 1) * 2 * 50, blue);
                    canvas.drawBitmap(dot[x][y], x*100, y*100,null);
                }
            } 

        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


}

0 个答案:

没有答案