accessing a layer’s methods

Store Forums Processing Layers General Discussion accessing a layer’s methods

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #548

    I’m a big fan of your layers library. Thank you.

    I have a sketch with a couple of layers, and I can’t seem to figure out how to access a layer’s methods.

    So, for instance, I have a layer definition

    public class L_PolyMesh extends Layer {

    void setup();{…}
    void draw(){…}
    void drawPolygons(){…}


    and in the main program, I create an instance of the layer

    void setup() {
    layers = new AppletLayers(this);
    L_PolyMesh canvas_mesh = new L_PolyMesh (this);
    l_mesh = layers.getLayer(0);

    My problem is that when I try to do:


    I get a warning that says “The function drawPolygons does not exist”. I’m sure I’m missing something, but I can’t figure out what that is. Your help would be appreciated.



    How is the variable “l_mesh” declared? Is it declared as type Layer?

    If so, then you need to cast it to the type L_PolyMesh:


    That is, you have to tell the compiler that your object is not only a Layer, but is specifically a L_PolyMesh object.

    Alternatively, you can declare l_mesh as type L_PolyMesh. Hope that makes sense.


    Sneaky. That worked. My knowledge of OOP is a bit hazy, but I’m trying. Thanks for your help.
    If I may ask another question, can you explain what this bit of code does to make the layers render?

    void paint(java.awt.Graphics g) {
    // This method MUST be present in your sketch for layers to be rendered!
    if (layers != null) {
    } else {
    } // end of paint()

    Specifically what is ‘g’? I’ve seen in some old bits of code that inside layers definitions, I’ll see lines like:

    img = g.get()

    Thanks again for your help.


    The variable ‘g’ is a reference to the Processing PGraphics object which performs the drawing in Processing.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.