gpt4 book ai didi

java - 第二个油漆覆盖第一个油漆

转载 作者:行者123 更新时间:2023-12-01 11:44:46 25 4
gpt4 key购买 nike

我有两种颜料,并将它们的颜色设置为不同的颜色。问题是第二个绘制覆盖了第一个绘制。

这是我的代码:

public class Score {
static Globals g = Globals.getInstance();
private Rect bounds = new Rect();
private Paint paintBG = new Paint();
private Paint paintFG = new Paint();
private int mid;

public Score(Paint paint) {
this.paintBG = paint;
this.paintFG = paint;

// PROBLEME
paintBG.setColor(Color.GRAY);
paintFG.setColor(Color.WHITE); // <-- this paint overrides the paint before
}

public void draw(Canvas canvas) {
String score = String.valueOf(g.getScore());
paintFG.getTextBounds(score, 0, score.length(), bounds);
mid = (canvas.getWidth() / 2) - (bounds.width() / 2);

// different "paints" but the same color
canvas.drawText(score, mid, 60, paintBG);
canvas.drawText(score, mid, 50, paintFG);
}
}

来自德国的最诚挚的问候。 :)

最佳答案

amahfouz 已经解释了这个问题。解决该问题的一种方法是使用 Paint 的复制构造函数。

public Score(Paint paint) {
paintBG = new Paint(paint);
paintFG = new Paint(paint);
paintBG.setColor(Color.GRAY);
paintFG.setColor(Color.WHITE);
}

关于java - 第二个油漆覆盖第一个油漆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29240211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com