How to draw GButton on PGraphics.

edited October 2013 in Library Questions

Hi! I am currently working on simple 2D game. I am using PGraphics as some sort os side panel, and I am planning to place my game ui there. Therefore I'd like to draw a GButton from g4p on it. Is it even possible? Please help

Answers

  • I am using PGraphics as some sort of side panel

    Why not use a GWindow or GPanel gor the controls

  • Except for buttons, I would also like to draw some images on side panel, and animate, rotate and scale them. The functions that are pretty simple to do in PGraphics. It doesn't have to be g4p, any button will do.

  • Is it possible to do such thind or do I have to implement my own buttons? I would be really grateful if someone have replied. I really need to do this

  • It is not possible to draw G4P controls to a separate PGraphics object.

    I am using PGraphics as some sort os side panel, and I am planning to place my game ui there.

    Why use a PGraphics object? Why not just say the left side will be for the game and the right side for the game UI?

  • edited November 2013

    It's a board game and i'd like to have a board in the centre and panels on the sides. And i'd like to scale and translate the board while leaving panels intact

  • This is not as difficult as it sounds because the G4P controls are drawn after the draw() method.

    In pseudocode the draw method will look like this

    void draw(){
        background(0); // clear the display ready for this frame
        pushMatrix(); // save the current matrix
    
        // translate, rotate, scale for your game
        // draw thw game board
    
        popMatrix(); // restore the matrix to draw UI controls
    
        fill(255); // background colour for your control panels
        noStroke();
        rect(0,0,lpw,height); // left panel background
        rect(0,width - rpw, rpw, height); // right panel background
    }
    

    where lpw and rpw are the control panel widths in pixels.

    When you create the G4P controls make sure their positions are over the panel areas.

    This has worked for me many times.

    HTH

  • Thank you for help :)

Sign In or Register to comment.