我有一个叫做“MapObject”的类,它允许你定义它是什么,它做什么。我最近为此添加了文本,它工作正常,但是碰撞是一个矩形,在某些情况下并不可怕,但是我更喜欢有一个与文本匹配的碰撞框(也就是检查 1x1 矩形是否与文本,但仍然可以在字母之间)
我尝试了以下方法:
GlyphVector vec = ob.font.createGlyphVector(new Canvas().getFontMetrics(ob.font).getFontRenderContext(), ob.text);
Shape textSh = vec.getOutline();
Area obSh = new Area(new Rectangle(x,y,o.width,o.height));
obSh.intersect(new Area(textSh));
boolean inter = !obSh.isEmpty();
但是它不起作用,我想是因为位置,但是我不知道如何在其中添加位置。谢谢。
慕娘9325324
相关分类