我有下一个问题。在我的项目中,当从层中添加或删除节点时,我需要将消息委托给第三方库。为了实现这一点,我以下面的方式扩展了 PLayer:
public class DelegateLayer extends PLayer {
private Delegate delegate = null;
private boolean delegationNeeded = false;
public DelegateLayer() {
super();
}
@Override
public void removeChildren(final Collection children) {
for (Object child : children) {
removeChild((PNode)child);
}
}
@Override
public void addChildren(final Collection children) {
for (Object child : children) {
addChild((PNode) child);
}
}
@Override
public void addChild(final PNode child) {
if (delegationNeeded) {
Preconditions.checkNotNull(delegate, "DelegateLayer: Delegate is not initialized");
delegate.delegateNodeAdded((CloudNode)child);
}
super.addChild(child);
}
@Override
public PNode removeChild(final PNode child) {
if (delegationNeeded) {
Preconditions.checkNotNull(delegate, "DelegateLayer: Delegate is not initialized");
delegate.delegateNodeRemoved((CloudNode)child);
}
return super.removeChild(child);
}
public void setDelegationNeeded(boolean needed) {
this.delegationNeeded = needed;
}
public void setDelegate(ClusterUpdateDelegate delegate) {
this.delegate = delegate;
}
}
我还将这个节点层添加到画布的相机中:
DelegateLayer nodeLayer = new DelegateLayer();
camera.addLayer(0, nodeLayer);
但是,在我将节点放置到图层并应用转换(将节点集中在点上)之后,什么也没有发生。但是,一旦我切换到 PLayer,我就可以使用camera.getLayer(0)
一切正常了。
那么,任何人都可以,请解释什么是错的?