So I have a sceneu2.ui table like this:
+--------------------------------------+
|+---------+ +------------+ +---------+|
|| Table 1 | | ScrollPane | | Table 2 ||
|+---------+ +------------+ +---------+|
+--------------------------------------+
| My Actor |
+--------------------------------------+
Inside the scrollpane
is another table
. The enclosure is also a table
. Table 1
, Table 2
and table
inside scrollpane
have same number of row.
My Actor
is simple image button actor that also support mouseover.
The problem is that, My Actor
doesn't appear at first (but it's boundary exists -- checked by table debug line) but when I scroll something in scrollpane
(with mouse) it appear for 2 seconds, and then begin to fade away. (the expected result should be it appear all the time)
What am I doing wrong?
The My Actor
class:
public class GameButton extends Actor {
public static abstract class Listener {
public abstract void onClick();
}
final Texture[] current;
final Listener listener;
boolean disabled;
int state = 0;
public GameButton(Texture[] current, final Listener listener) {
this.current = current;
setWidth(current[0].getWidth());
setHeight(current[0].getHeight());
this.listener = listener;
disabled = false;
this.addListener(new InputListener() {
boolean just_up = false;
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
state = 2;
return true;
}
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
state = 0;
if (hit(x, y, false) != null) {
just_up = true;
state = 1;
if (listener != null && !disabled)
listener.onClick();
}
}
@Override
public void enter (InputEvent event, float x, float y, int pointer, Actor fromActor) {
if (state == 0)
state = 1;
}
@Override
public void exit (InputEvent event, float x, float y, int pointer, Actor toActor) {
if (!just_up)
state = 0;
just_up = false;
}
});
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
@Override
public void draw(SpriteBatch batch, float _) {
super.draw(batch, _);
batch.draw(current[disabled ? 0 : state], getX(), getY(), getWidth(), getHeight());
}
}
The code which is used to add this to table:
btnBack = new GameButton(Assets.btnBack, 0, 0, new GameButton.Listener() {
@Override
public void onClick() {
/* removed */
}
});
add(btnBack).colspan(3).right().bottom().height(128);
I realize this question is 2 years old, but I also had this problem so thought I would post my solution. For me it was simply a case of setting the scroll bar fade to false, using
ScrollPane scroll = new ScrollPane();
scroll.setFadeScrollBars(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With