【问题标题】:Visualisation of a boardgame棋盘游戏的可视化
【发布时间】:2021-12-29 03:03:38
【问题描述】:

我是 android studio 的新手,我现在学到了很多东西。但我现在被困住了,我想创建一个类似于容器的东西,用于具有单个字段的 16x7 棋盘游戏。我认为有更好的方法可以做到这一点,我尝试了 2 个小时,但没有成功。现在我正在使用网格视图将我的 String[] 与一个数组适配器显示为一个简单的可选列表项,但它不能正确缩放,我需要向下滚动以查看所有字段,这对一个电子游戏。

Tl,dr:我想显示一个包含 112 个元素的数组,比如棋盘游戏,我可以使用什么容器来创建这些单独的字段,甚至可以设置行 (7) 和列 (16) 的数量,以及像真正的棋盘游戏一样简单地显示它?

【问题讨论】:

    标签: android scaling


    【解决方案1】:

    我会将位图图块渲染到画布上。下面的代码只是一个大纲:

    // You will set this frameBuffer to an ImageView in the app's main screen.
    // You should set the ImageView's ScaleType properly.
    Bitmap frameBuffer = Bitmap.createBitmap(
        TILE_SIZE * 16, TILE_SIZE * 7, Bitmap.Config.ARGB_8888
    );
    Canvas canvas = new Canvas(frameBuffer);
    Paint paint = new Paint();
    
    for (int y = 0; y < 7; y++) {
        for (int x = 0; x < 16; x++) {
            // You are supposed to define bitmapTiles.get() method elsewhere.
            canvas.drawBitmap(
                bitmapTiles.get(x, y), TILE_SIZE * x, TILE_SIZE * y, paint
            );
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      • 1970-01-01
      • 2010-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      相关资源
      最近更新 更多