Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

LibGDX: Problems creating custom actor

$
0
0

I am creating a custom class that extends from Actor,just like this:

public class MyActor extends Actor {
ProgressBar bar;
Label nameLabel;
TextButton button;
public MyActor(String name, Skin skin){
    nameLabel = new Label(name, skin);
    button = new TextButton("Whatever",skin);
    bar = new ProgressBar(0f,5f,1f,false,skin);


}
@Override
public void act(float delta) {
    super.act(delta);
    bar.setBounds(getX(), getTop()-getHeight() / 3f, getWidth(), getHeight() / 3f);
    nameLabel.setBounds(getX(), getY()+getHeight() / 3f, getWidth(), getHeight() / 3f);
    button.setBounds(getX(), getY(), getWidth(), getHeight() / 3f);
}

@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    bar.draw(batch, parentAlpha);
    nameLabel.draw(batch, parentAlpha);
    button.draw(batch,parentAlpha);
} }

Then I try to add it to a Table:

Table myTable = new Table();
myTable.add(myActor).row();

But it always gets drawn in the 0,0 coordinates!, what am I doing wrong? Do I have to override another method?


Viewing all articles
Browse latest Browse all 434

Trending Articles