我在我的游戏中使用GL_SCISSOR_TEST,但我遇到了一个奇怪的问题。 GL_SCISSOR_TEST在属于舞台的actor的draw()中被启用(然后被禁用)。
奇怪的是,某个随机但特定的参与者正受到GL_SCISSOR_TEST的影响,即使未在其draw()方法中对其进行定义。
奇怪的是,只有最后一次尝试在该actor的draw()方法中绘制内容的尝试失败了。如果最后一行是位图字体绘制,则不显示文本。如果是纹理的batch.draw,则不显示该纹理。如果我将文本或纹理移动到本来与该角色完全无关的其他actor内最初由GL_SCISSOR_TEST裁剪的区域内,则该文本或纹理变得可见,因此很明显GL_SCISSOR_TEST由于某种原因影响了此actor,但我不知道什么。
这是使用GL_SCISSOR_TEST的actor的draw方法:
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
Gdx.gl.glScissor((int)inventoryPanel.getX(),
(int)inventoryPanel.getY() + (int)(inventoryPanel.getHeight() * 0.1f),
(int)inventoryPanel.getWidth(), (int)(inventoryPanel.getHeight() * 0.72f));
float itemRatio = itemBg.getWidth() / (float)itemBg.getHeight();
float itemWidth = inventoryPanel.getWidth() * 0.8f;
float itemHeight = itemWidth / itemRatio;
itemX = inventoryPanel.getWidth() * 0.075f;
float startingY = inventoryPanel.getHeight() * 0.83f - itemHeight
+ inventoryPanel.getScrollIndicator();
itemY = startingY - itemIndex * itemHeight;
batch.draw(itemBg, itemX, itemY, itemWidth, itemHeight);
float itemIconWrapperSize = itemHeight * 0.625f;
float itemNameX = itemX + itemWidth * 0.04f;
float itemIconWrapperX = itemX + itemWidth * 0.032f;
float itemIconWrapperY = itemY + itemHeight * 0.058f;
batch.draw(itemIcon, itemIconWrapperX, itemIconWrapperY, itemIconWrapperSize, itemIconWrapperSize);
if(data.EquippedBy != null)
batch.draw(itemIconActive, itemIconWrapperX, itemIconWrapperY, itemIconWrapperSize, itemIconWrapperSize);
float itemNameY = itemY + itemHeight * 0.9f;
fontGenerator.getFonts().fontCharacterName.draw(batch,
FontHelper.getColoredString(data.ItemName, Fonts.DEFAULT_TEXT_COLOR),
itemNameX,
itemNameY);
itemButtonX = itemX + itemWidth * 0.65f;
itemButtonY = itemY + itemHeight * 0.71f;
float itemButtonRatio = itemButton.getWidth() / (float)itemButton.getHeight();
itemButtonHeight = itemHeight * 0.25f;
itemButtonWidth = itemButtonHeight * itemButtonRatio;
setBounds(itemButtonX, itemButtonY, itemButtonWidth, itemButtonHeight);
batch.draw(pressingButton || (activeContext == InventoryContexts.CHARACTER_PANEL_OPEN && data.EquippedBy != null) ?
getActiveButtonTextureForContext() : itemButton,
itemButtonX, itemButtonY, itemButtonWidth, itemButtonHeight);
fontGenerator.getFonts().fontWorldViewObjectName.draw(batch,
getButtonNameForContext(),
itemButtonX,
itemButtonY + itemButtonHeight * 0.6f,
itemButtonWidth,
Align.center,
false);
float descriptionX = itemX + itemWidth * 0.38f;
float descriptionY = itemY + itemHeight * 0.62f;
float descriptionWidth = itemWidth * 0.6f;
fontGenerator.getFonts().fontWorldViewObjectName.draw(batch,
getItemDescription(),
descriptionX,
descriptionY,
descriptionWidth,
Align.left,
true);
batch.flush();
Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
}
这是受影响演员的绘制方法:
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(activeTab == 3 ? activeTabTexture : tabTexture, getX(), getY(), getWidth(), getHeight());
fontGenerator.getFonts().fontWorldViewObjectName.getData().setScale(0.8f);
fontGenerator.getFonts().fontWorldViewObjectName
.draw(batch,
activeTab == 3 ? FontHelper.getColoredString("POTIONS", "#000000") : "POTIONS",
getX(), getY() - getHeight() * 0.2f, getWidth(), Align.center, false);
fontGenerator.getFonts().fontWorldViewObjectName.getData().setScale(1f);
}
正如我所说,如果我将batch.draw移到方法的最后一行,则正在绘制文本POTIONS,但没有绘制纹理。如果我将其保留为当前状态,则不会绘制文本。
这些演员唯一的共同点是他们处于同一阶段。 有任何想法吗?这让我发疯。