【发布时间】:2019-03-15 14:01:58
【问题描述】:
我实际上是在基于网格的 Android Studio 上做一个游戏,我用这个来绘制:
public void dessin(Canvas canvas){
paint.reset();
TenGame theGame=gam.getTenGame();
canvas.drawColor(Color.YELLOW);
paint.setColor(Color.BLACK);
for(int x=0;x<canvasWidth;x+=cellSize){
canvas.drawLine(x,0,x,canvasWidth,paint);
}
for(int y=0;y<canvasWidth;y+=cellSize){
canvas.drawLine(0,y,canvasWidth,y,paint);
}
paint.setTextSize(50);
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
PositionList plist=theGame.getSelectedGroup();
for(int x=0;x<5;x++){
for(int y=0;y<5;y++){
Position p=new Position(x,y);
if (theGame.get(p)!=null) {
canvas.drawText(Integer.toString(theGame.get(p)), (x * cellSize) + 15, (cellSize + y * cellSize) - 15, paint);
}
else{
canvas.drawText("", (x * cellSize) + 15, (cellSize + y * cellSize) - 15, paint);
}
}
}
}
当我触摸网格中的一个单元格时,我想更改背景颜色。
我认为对我来说最好的解决方案是做一个drawRect(),但我不知道我应该做哪个维度。
我在库中有游戏模型,可以得到Position (x, y)。
【问题讨论】:
标签: java android canvas drawing