I have the following (pseudo) code
root = _iface.createRoot(...)
Label l = new Label("hello world");
anim = Animator.create();
anim.delay(1500).then().add(root.layer, l.layer);
anim.delay(1000).then().action(new Runnable() {
public void run() {
// root.add(l);
System.out.println("it works");
}
});
the it work’s line gets printed ok, so I assume I’m updating the animation right, but the label is never added to the scene!
If I uncomment the root.add(l) inside the Runnable it works as expected (the label is added after 1 second), but it doesn’t get added with anim.delay(1500).then().add(root.layer, l.layer);
any idea whay I’m doing wrong?
You can’t just add the layer of a TPUI
Widgetto another layer and expect theWidgetto render properly. A widget must be added to its parent viaGroup.add.The animation code you are using is more designed for animating raw PlayN layer’s than UI elements. UI elements are generally laid out using a
LayoutManagerwhich controls where the layer is positioned. If you tried to animate the layer directly, you would confuse the layout manager and generally mess everything up.That said, it’s pretty safe to animate the
Rootof the interface, because that anchors a whole UI into the PlayN scene graph.If you really want to try what you’re doing above, don’t use
Animator.adduse:(like you have above) which properly adds the
Labelto theRoot, and triggers validation and rendering of theLabel.