小编JCH*_*530的帖子

为Android游戏绘制方形网格时遇到问题

我希望它在屏幕中央显示为 7 x 7 方形网格,但是正如您在我当前的代码中看到的那样,垂直线位于正确的位置,但水平线不在。我相信这是一个简单的修复,任何帮助将不胜感激 -

public class GameGrid extends View {

    Paint black = new Paint();

    public GameGrid(Context context) {
        super(context);

        black.setColor(Color.BLACK);
        black.setStrokeWidth(8);
    }

    @Override
    public void onDraw(Canvas canvas) {

        float startX;
        float stopX;
        float startY;
        float stopY;

        int width = canvas.getWidth();
        int height = canvas.getHeight();

        int gridSize = 7;
        int gridSpacing = width / gridSize;

        //Vertical Grid-lines
        for (int i = 0; i < gridSize; i++) {

            startX = width / 2 - height / 2;
            stopX = …
Run Code Online (Sandbox Code Playgroud)

java grid android android-studio

3
推荐指数
1
解决办法
1366
查看次数

标签 统计

android ×1

android-studio ×1

grid ×1

java ×1