Setting img as background - Coordinate out of bounds

edited September 2016 in Questions about Code

Hey guys, I'm trying to display and image as my background in the void setup() but it shows me the ArrayIndexOutOfBoundException: Coordinate out of bounds! error. However, when I use background(img); in the void draw() , it works.

PImage sourceImg;
int dw, dh;

void setup () {
  sourceImg = loadImage("test2.jpg");
  surface.setResizable(true);
  dw = sourceImg.width;
  dh = sourceImg.height;
  surface.setSize(dw, dh);
  background(sourceImg); //HERE IT GIVES ME THE ERROR
}

void draw() {
  //background(sourceImg); //HERE IT WORKS
}

I don't know how to fix this. I need the background image to be drawn one time at the start of the program. What does that error mean?

Thx in advance!

Answers

Sign In or Register to comment.