We are about to switch to a new forum software. Until then we have removed the registration on this forum.
From my understanding, setting a background image in processing requires the size of the window to match the dimension of the image.
PImage img = loadImage("background.jpg"); //a 100x100 background image.
size(100,100);
background(img);
However, since size() does not take in variables, how are we suppose to define a background with variable dimensions?
I have tested with the surface.setSize() function but it does not see to work.
Example:
PImage img = loadImage("background.jpg"); //a 100x100 background image.
surface.setSize(img.width,img.height);
background(img);
Answers
It works! But doesn't the setting function gets called first? Is it due to delay that the setup function is able to read the size()?
Yes, settings() is called even before setup(). Also needed for size() using variables as its arguments:
https://Processing.org/reference/settings_.html
I'm still using Processing v. 3.1.2. And so statementwhile (bg.width <= 1) delay(100);
isn't needed here.However, for newer versions, loadImage() is asynchronous by default, and doesn't block!:-SSIt means it can reach statement
size(bg.width, bg.height);
before the image is loaded & ready!That's why I have that delay(); so it awaits width get bigger than;;)1
. Meaning it's ready!On 2nd thought, I guess it is save() & saveFrame() function which are async, not loadImage()! b-(
Please disregard my explanation before. :-\". Gonna remove the delay() too, not needed! :P