gpt4 book ai didi

java - Java中除空格外的屏幕填充

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

我正在尝试使用 Java 中的 Graphics2D 对象渲染 war 迷雾。目前,我正在这样渲染。

// Color the screen black
Color color = new Color(0, 0, 0, 200);
graphics.setColor(color);
graphics.fillRect(0, 0, entity.getWorld().getGame().getWidth(), entity.getWorld().getGame().getHeight());
// Make a rectangle around the Entity that is normal
color = new Color(0, 0, 0, 0);
graphics.setColor(color);
PositionComponent2D data = (PositionComponent2D) entity.getComponent("pos");
Vector2D pos = data.getAABB().getPosition();
graphics.fillRect((int) pos.getX() - 20, (int) pos.getY() - 20, 40, 40);

它给出了我正在寻找的效果,除了代码的第二部分不起作用。有没有什么方法可以渲染屏幕上除了玩家附近以外的任何地方,以产生 war 迷雾效果?

最佳答案

您需要使用 composite对于您的第二次绘图调用...类似这样的内容(免责声明:我没有尝试运行此代码,但这应该是一个起点):

// Color the screen black
Color color = new Color(0, 0, 0, 200);
graphics.setColor(color);
graphics.fillRect(0, 0, entity.getWorld().getGame().getWidth(), entity.getWorld().getGame().getHeight());
// Make a rectangle around the Entity that is normal
Composite oldComposite = graphics.getComposite();
graphics.setComposite(AlphaComposite.CLEAR);
PositionComponent2D data = (PositionComponent2D) entity.getComponent("pos");
Vector2D pos = data.getAABB().getPosition();
graphics.fillRect((int) pos.getX() - 20, (int) pos.getY() - 20, 40, 40);
graphics.setComposite(oldComposite);

关于java - Java中除空格外的屏幕填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25171382/

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