Layer origin, positioning... any way to debug?

31 views
Skip to first unread message

kal...@gmail.com

unread,
Nov 5, 2015, 6:35:21 AM11/5/15
to PlayN
I'm a little confused by the origin and positioning of layers. Is there a way to visually debug these things? Something like wireframe rendering, displaying the name and offset of all elements on the layer, etc.

Brigt Vik

unread,
Nov 5, 2015, 8:13:08 AM11/5/15
to PlayN, kal...@gmail.com
Note that I'm still using PlayN 1.9 - this may not work correctly in 2.0!

What I have done when I'm confused about where a layer is gone off to, is to paint it completely with a colour. This way, if the reason why I'm not seeing it is accidentally painting stuff outside of the image, I can see where the image is actually at, at least.

Additionally, and I think this is more in line with what you're suggesting, I've added a name attribute to the AbstractLayer class and changed its toString to print it. Each of my classes handling layers will set their own name on it. When stopping on a breakpoint I can see the tree of named GroupLayers, their contents and each element's transformation values in the debugger.

This is needed in Layer.java:

  public void setName(String layerName);

This is needed in AbstractLayer.java (note that the toString method already exists, replace it):

  private String name;
  @Override
  public void setName(String name) {
    this.name = name;
  }

  @Override
  public String toString () {
    StringBuilder bldr = new StringBuilder();
    if(name != null)
      bldr.append(name);
    else
    {
      String cname = getClass().getName();
      bldr.append(cname.substring(cname.lastIndexOf(".")+1));
    }

    bldr.append(" [hashCode=").append(hashCode());
    bldr.append(", tx=").append(transform());
    if (hitTester != null) bldr.append(", hitTester=").append(hitTester);
    return bldr.toString();
  }

If this doesn't help me, I add calls to print out the layer structure of the root or a lower layer at given points in the code using this:

public class LayerUtil
{
public static void printLayerStructure()
{
GroupLayer root = graphics().rootLayer();
StringBuilder s = new StringBuilder();
s.append("Root\n");
for(int i = 0; i < root.size(); i++)
{
printLayerStructure(s, root.get(i), 1);
}
System.out.println(s);
}

public static void printLayerStructure(StringBuilder s, Layer l, int indent)
{
if(l instanceof GroupLayerGL || l instanceof ImageLayerGL)
{
for(int i = 0; i < indent; i++)
s.append(" ");
s.append(l.toString());
s.append("\n");
}
if(l instanceof GroupLayerGL)
{
GroupLayerGL g = (GroupLayerGL)l;
for(int i = 0; i < g.size(); i++)
{
printLayerStructure(s, g.get(i), indent + 1);
}
}
}
}

It will output stuff such as this below. You may want to fiddle with the toString method to get an output you can most easily read.

Root
  MenuScreenGroup [hashCode=487694075, tx=affine [+1.0 +0.0 +0.0 +1.0 +0.0+0.0]
    MenuScreenLayer [hashCode=76432244, tx=affine [+1.0 +0.0 +0.0 +1.0 +0.0+0.0]
    StatusLayer [hashCode=1030228826, tx=affine [+1.0 +0.0 +0.0 +1.0 +736.0+0.0]
  LoadingScreenGroup [hashCode=1264413185, tx=affine [+1.0 +0.0 +0.0 +1.0 +0.0+0.0]
    LoadingScreen [hashCode=1243806178, tx=affine [+1.0 +0.0 +0.0 +1.0 +0.0+0.0]

Hope it helps!
Reply all
Reply to author
Forward
0 new messages