In scene2d, the method stage.draw() is supposed to fire the draw method of all actors, but in my case it not fire even a single one. This is my code:
Setup:
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);
}
Render method:
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);
}
Actor:
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);
}
}
Resize:
@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);
}
The debug string in actor's constructor is printed, but the debug string in the actor's draw is not printer. I have test to draw in the render a texture with batch.draw, and works fine. But the actor is never render.
act
get called? If yes, it is possible, that yourActor
is out of theStage
sViewport
and so it gets culled, meaningdraw()
will never be called. – Robert PIntroScreen
constructor? – Robert PStage
has its own camera andSpriteBatch
. So theSpriteBatch
you set up in the constructor and in the resize is never used. You need to callstage.setSpriteBatch
so thatstage
uses yourSpriteBatch
– Robert P