在scene2d中,stage.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绘制渲染纹理,并且工作得很好。但这位演员从不渲染。
发布于 2014-04-17 16:26:52
问题在于show()方法,它重新初始化了这个阶段。show()是在构造函数之后调用的,因此这个阶段没有在构造函数中声明的任何内容。评论台词,解决问题。
public void show()
{
//stage = new Stage();
}此外,我已经把相机对准舞台上的摄像机,就像Springrbua所说的那样。
stage.setCamera(camera);https://stackoverflow.com/questions/23132166
复制相似问题