Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Libgdx stage.draw()不要解雇演员_Libgdx_Scene2d - Fatal编程技术网

Libgdx stage.draw()不要解雇演员

Libgdx stage.draw()不要解雇演员,libgdx,scene2d,Libgdx,Scene2d,在scene2d中,方法stage.draw()应该触发所有参与者的draw方法,但在我的例子中,它甚至不会触发一个。 这是我的代码: 设置: public IntroScreen(DirectedGame game) { super(game); batch = new SpriteBatch(); camera = new OrthographicCamera(Constants.EDITOR_GUI_WIDTH, Constants.EDITOR_GUI_HEIG

在scene2d中,方法stage.draw()应该触发所有参与者的draw方法,但在我的例子中,它甚至不会触发一个。 这是我的代码:

设置:

public IntroScreen(DirectedGame game)
{
    super(game);

    batch = new SpriteBatch();
    camera = new OrthographicCamera(Constants.EDITOR_GUI_WIDTH, Constants.EDITOR_GUI_HEIGHT);
    camera.position.set(0, 0, 0);
    camera.setToOrtho(false);
    camera.update();

    stage = new Stage();
    achisoft = new Text("AchiSoft");
    achisoft.setVisible(true);
    achisoft.size(200);
    achisoft.setPosition(50, 50);
    stage.addActor(achisoft);
    Gdx.app.debug("stage","num_actors="+stage.getActors().size);

}
渲染方法:

public void show()
{
    stage = new Stage();
}

@Override
public void render(float deltaTime)
{
    getInputProcessor();
    Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    stage.act(deltaTime);
    stage.draw();
    //Gdx.app.debug("render","deltaTime="+deltaTime);
}
演员:

public class Text extends Actor
{
    BitmapFont fontt;
    String text;
    Texture textur;

    public Text(String cad)
    {
        text=cad;
        fontt=Assets.instance.fonts.defaultBig;
        Vector2 res = new Vector2();
    res.set(512, 512);
    Pixmap pixmap = new Pixmap(512, 512, Format.RGBA8888);
    pixmap.setColor( 0, 1, 0, 1f );
    pixmap.fillRectangle(1,1,256,256);
    pixmap.setColor( 1, 0, 0, 1f );
    pixmap.fillRectangle(257,257,256,256);
    textur = new Texture(pixmap);
    pixmap.dispose();
    Gdx.app.debug("texture","entra");
    }

    @Override
    public void draw(Batch batch, float parentAlpha)
    {
        fontt.setColor(1, 0, 0, 1); // red
    fontt.draw(batch, text, 20, 20);
    batch.draw(textur,50,50);
    Gdx.app.debug("texture","se pinta");
    }

    @Override
    public Actor hit(float x, float y, boolean touchable)
    {
        // TODO Auto-generated method stub
        return super.hit(x, y, touchable);
    }
}
调整大小:

@Override
public void resize(int width, int height)
{
    stage.setViewport(width, height, false);
    Gdx.app.debug("size",width+ " "+height);
    camera.setToOrtho(false, width, height);
    batch.setProjectionMatrix(camera.combined);
}
将打印参与者构造函数中的调试字符串,但参与者绘图中的调试字符串不是打印机。
我已经测试了在渲染中使用batch.draw绘制纹理,效果很好。但是演员永远不会被渲染。

问题在于show()方法,它重新初始化了舞台。show()是在构造函数之后调用的,因此stage没有在构造函数中声明任何内容。 评论行,解决了问题

public void show()
{
    //stage = new Stage();
}
另外,正如斯普林布亚所说,我已经将摄像机设置为舞台摄像机和主摄像机

stage.setCamera(camera);

act
是否接到呼叫?如果是,您的
Actor
可能不在
阶段
s
视口
中,因此它被剔除,这意味着将永远不会调用
draw()
。我认为Actor在视口中,每个渲染阶段中阶段视口的首次打印:x=1920.0 y=1080.0是否使用在
IntroScreen
构造函数中创建的相机和spritebatch?我还使用了resize()函数。这几乎是该屏幕的全部代码。我只使用你看到的东西。我在其他屏幕上以不同的方式成功地使用了scene2d对象,但在IntroScreen中,像这样的简单绘图不起作用。我浪费了太多的时间在一个我看不见的小错误或打字错误上……只需要注意一件事:
Stage
有自己的相机和
SpriteBatch
。因此,永远不会使用在构造函数和调整大小中设置的
SpriteBatch
。您需要调用
stage.setSpriteBatch
,以便
stage
使用您的
SpriteBatch