G4P and PImage

edited May 2017 in Library Questions

Hi all

Just a quick question about multiple screens. I'd like to include 2 screens in a project I'm doing. I came across G4P as a way to do this. However I'm having some difficulty incorporating changes (such as transform or scale) to PImages in the second screen. My code so far is below:

import g4p_controls.*;

GWindow window;

int r;
int g;

Boolean MTshow;
PImage mustemp;

public void setup() {
  size(480, 320);
  window = GWindow.getWindow(this, "My Window", 100, 50, 480, 320, P2D);
  window.addDrawHandler(this, "windowDraw");
  mustemp = loadImage("mustemp.jpg");

public void draw() {
  background(r, g, 50);
  if (mousePressed) {
    MTshow = true;

public void windowDraw(PApplet app, GWinData data) {
  app.background(255, 0, 0);
  r = app.mouseX;
  g = app.mouseY;

  int x = 0;

  if (MTshow) {
    app.image(mustemp, x, 0, app.width, app.height);

Currently, the 'x++' command doesn't seem to be doing anything. Ideally, I'd like to include all my image data into it's own class, but that doesn't seem to be working either. Does anyone have any advice?



  • Answer ✓

    That is because line 30 is setting x=0. You need to change that line or remove it and move it to a global scope.


  • Oh wow, thank you. There's always a simple solution I never think of! Would this also work if I put the image in it's own class? :)

  • It really depends on your design, on what you want to do.


  • Hi kfrajer. Thanks for all your help. I decided to forego creating classes for the images. I was really just overcomplicating something that turned out to be relatively simple. Thanks again! :)

Sign In or Register to comment.