在我的游戏中,有敌人徘徊,他们的draw()
方法很简单:
core.displayBuffer
是一个PGraphics
对象,在draw()
的末尾绘制在屏幕上。
if(facingRight) {
core.displayBuffer.image(image,
x, y + offsetY, 80, 80);
} else {
float tX = -core.camera.x+core.game.width/2f + x;
float tY = -core.camera.y+core.game.height/2f+ y;
core.displayBuffer.pushMatrix();
core.displayBuffer.translate(core.camera.x-core.game.width/2f,
core.camera.y-core.game.height/2f);
core.displayBuffer.translate(tX, tY);
core.displayBuffer.scale(-1, 1);
core.displayBuffer.image(image,
-80, offsetY, 80, 80);
core.displayBuffer.popMatrix();
}
然后,当我们要绘制墙壁时,我们只需绘制一个彩色矩形,如下所示:
core.displayBuffer.noStroke();
if(destroyed) {
core.displayBuffer.fill(0, 0, 0, 16);
core.displayBuffer.rect(x, y, w, h);
} else {
core.displayBuffer.fill(64);
core.displayBuffer.rect(x, y - WALL_HEIGHT, w, h);
core.displayBuffer.fill(32);
core.displayBuffer.rect(x, y + h - WALL_HEIGHT, w, WALL_HEIGHT);
}
但是由于某些原因,墙壁有敌人的纹理吗?这是绘制对象的循环:
PMatrix displayMatrix = displayBuffer.getMatrix();
PMatrix bloomMatrix = bloomLayer.getMatrix();
PStyle displayStyle = displayBuffer.getStyle();
PStyle bloomStyle = bloomLayer.getStyle();
onScreenObjects.forEach(o -> {
displayBuffer.setMatrix(displayMatrix);
bloomLayer.setMatrix(bloomMatrix);
displayBuffer.style(displayStyle);
bloomLayer.style(bloomStyle);
o.draw(this);
});
displayBuffer.setMatrix(displayMatrix);
bloomLayer.setMatrix(bloomMatrix);
displayBuffer.style(displayStyle);
bloomLayer.style(bloomStyle);
这里是结果示例,墙壁周围的红色矩形绘制不正确。
另外子弹由于某种原因在闪烁吗?当我不在屏幕上绘制敌人(或者我只绘制矩形)时,这两个bug不会出现,这意味着image()
在后台做些奇怪的事情吗?
项目的源代码位于https://github.com/Matrx007/TheLostBits
如有需要,请询问其他信息!
Nvidia Quadro 4000。 显卡驱动程序从2016年开始,无法升级,所有其他游戏都运行正常。 处理版本:3.5.3(库) 操作系统和操作系统版本:Windows 10 build 17134
可能的原因/解决方案:
也许image()
操纵着当前使用的纹理,而rect()
使用了纹理?
解决方案是,处理一次不能使用多个PGraphics。我曾在两个PGraphics上调用beginDraw(),并且同时绘制了两个图形,现在我将它们分离了,该错误消失了!此处提供更好的解释:https://github.com/processing/processing/issues/5863