gpt4 book ai didi

java - libgdx - Group.draw 中的 ShapeRenderer 以错误的颜色呈现

转载 作者:行者123 更新时间:2023-12-02 09:39:13 26 4
gpt4 key购买 nike

我的群组:

public class GShape extends Group{
private ShapeRenderer shape;

public GShape() {
super();
shape = new ShapeRenderer();
}

@Override
public void draw(SpriteBatch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
shape.begin(ShapeType.Line);
Gdx.gl10.glLineWidth(5);
shape.setColor(1, 1f, 1f, 1f);
shape.line(0, 0, 200, 100);
shape.end();
}
}

主要:

public class GameControl implements ApplicationListener {
private Stage stage;
private GShape gShape;

@Override
public void create() {
stage = new Stage(480,320,false);

Texture t = new Texture(Gdx.files.internal("data/the200.png"));
Image i = new Image(t);
stage.addActor(i);
gShape = new GShape();
stage.addActor(gShape);
}

@Override
public void dispose() {
}

@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.draw();
// gShape.render();
}

@Override
public void resize(int width, int height) {
}

@Override
public void pause() {
}

@Override
public void resume() {
}
}

形状的颜色不是白色?为什么?

http://nw7.upanh.com/b3.s38.d3/352dd792eb77ce6df204a7af47ae1ac6_55348087.cos.jpg?rand=0.19125773780979216

最佳答案

您可能会得到不一致的结果,因为您混合了 SpriteBatchShapeRenderer 上下文。这两个都期望它们在 OpenGL 中“存储”的状态在 begin()end() 调用之间得到维护。

SpriteBatch begin() 已经执行的上下文中调用 Actor draw() 方法已被调用,因此您需要在开始 ShapeRenderer 之前结束它。 (并且返回之前需要重新启动 SpriteBatch

像这样:

@Override
public void draw(SpriteBatch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
batch.end(); // ** End the batch context
shape.begin(ShapeType.Line);
// .. draw lines ...
shape.end()
batch.begin(); // ** Restart SpriteBatch context that caller assumes is active
}

关于java - libgdx - Group.draw 中的 ShapeRenderer 以错误的颜色呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16381106/

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